using com.hnshituo.core.webapp.vo;
using Common;
using Common.vo.pb;
using Infragistics.Win;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;
using JC_MeasuringSystem;
using MeterModuleLibrary;
using MeterPlugInLibrary;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Threading;
using System.Windows.Forms;
using Newtonsoft.Json;

namespace BeltScaleSystem

{
    /// <summary>
    /// 皮带结净数据补录  包含已审核未审核
    /// </summary>
    public partial class frmBeltScaleActualinfo_addendum : Form
    {
        public frmBeltScaleActualinfo_addendum()
        {
            InitializeComponent();
        }

        //菜单栏事件
        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "查询":
                    QueryScaleActualinfo();
                    break;
                case "新增":
                    AddScalePrediction();
                    break;
                case "修改":
                    UpdateScalePrediction();
                    break;
                case "导出":
                    ExporterScaleActual();
                    break;
                case "删除":
                    DeleteAndRecoverScaleActual(1);
                    break;
                case "还原":
                    DeleteAndRecoverScaleActual(2);
                    break;
            }
        }

        #region 自定义变量
        private string userId = "", userName = ""; //用户ID用户名
        private MeterWorkBeltActualService BeltActualService = new MeterWorkBeltActualService();
        private CoreAppUser userinfo = null;
        private DataTable dtMaterial;//物料数据源
        private DataTable dtMaterial2;//物料数据源
        private DataTable dtcustomerSupplier;//发货单位数据源
        private DataTable dtPoint;//计量点数据源
        MeterBaseMatterInfoService meterBaseMatterInfo = new MeterBaseMatterInfoService();//物料服务
        MeterBaseScalePointService monitorService = new MeterBaseScalePointService();
        MeterBaseCustomerSupplierService customerSupplierService = new MeterBaseCustomerSupplierService();
        private Boolean IsBatch = false;
        #endregion

        #region 菜单栏方法
        //实绩查询
        private void QueryScaleActualinfo() {
            try
            {
                if (DateTime.Compare(dtStartTime.Value, dtEndTime.Value) > 0)
                {
                    MessageBox.Show("开始时间不能大于结束时间");
                    return;
                }
                MeterWorkBeltActual actual = new MeterWorkBeltActual();
                DataTable dtScaleTable = dataTable2.Clone();
                CommonPage<MeterWorkBeltActual> cp = new CommonPage<MeterWorkBeltActual>();
                if (checkDate.Checked)
                {
                    cp.startTime = dtStartTime.Text.ToString();
                    cp.endTime = dtEndTime.Text.ToString();
                    if (cbDateFlag.SelectedIndex == 0) {
                        actual.startTime = dtStartTime.Value;//不为空即可
                    }
                    if (cbDateFlag.SelectedIndex == 1)
                    {
                        actual.endTime = dtStartTime.Value;//不为空即可
                    }
                    if (cbDateFlag.SelectedIndex == 2)
                    {
                        actual.checkTime = dtStartTime.Value;//审核时间  就是发布时间   不为空即可
                    }
                }
                if (cmMatName.Text.ToString() != "全部")
                {
                    actual.newMatName = cmMatName.Text.ToString();
                }
                if (cbfahuo.Text.ToString() != "全部")
                {
                    actual.newSupplier = cbfahuo.Text.ToString();
                }
                if (cbshouh.Text.ToString() != "全部")
                {
                    actual.receivingUintName = cbshouh.Text.ToString();
                }
                if (ckShipNo.Checked) {
                    if (ShipnoTxt_1.Text.ToString() != null && ShipnoTxt_1.Text.ToString().Trim() != "")//船号
                    {
                      actual.shipNo = ShipnoTxt_1.Text.ToString(); 
                    }
                }
                
                if (cmbState.Text.ToString() != "全部" && cmbState.Text.ToString() != "" )
                {
                    actual.valueFlag = cmbState.Value.ToString();
                }
                if (!Rbtn_AB.Checked)
                {
                    if (Rbtn_A.Checked) {
                        actual.scaleName = Rbtn_A.Text.ToString().Substring(0,1);
                    }
                    if (Rbtn_B.Checked)
                    {
                        actual.scaleName = Rbtn_B.Text.ToString().Substring(0, 1);
                    }
                }
                if (moteTxt_1.Text.ToString().ToString().Trim() != "")
                {
                    actual.unloadSite = moteTxt_1.Text.ToString().Trim();
                }
                cp.param = actual;
                
                RESTfulResult<List<MeterWorkBeltActual>> rms = BeltActualService.doQueryAndMultiple(cp);
                if (rms.Succeed)
                {
                    if (rms.Data != null && rms.Data.Count > 0)
                    {
                        dtScaleTable = rms.Data.ListToDataTable<MeterWorkBeltActual>();

                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable2, true);
                        string aa = "";
                        foreach (UltraGridRow ugr in beltActualGrid.Rows)
                        {
                            if (ugr.Cells["newMatName"].Value.ToString().Contains("焦炭"))
                            {
                                ugr.Cells["unloadSite"].Value = ugr.Cells["unloadSite"].Value.ToString() + "含焦粉";
                            }
                           
                            if (ugr.Cells["valueFlag"].Value.ToString() == "0")
                            {
                                ugr.Appearance.BackColor = Color.Red;
                            }
                            else if (ugr.Cells["checkFlag"].Value.ToString() == "1")
                            {
                                ugr.Appearance.BackColor = Color.YellowGreen;
                            }
                            else
                            {
                                ugr.Appearance.BackColor = Color.White;
                                //ugr.Cells["forwardingUnitName"].Value = "";
                                //ugr.Cells["forwardingUnitName"].Appearance.BackColor = Color.Gray;
                            }
                        }
                        ClsControlPack.RefreshAndAutoSize(beltActualGrid);
                    }
                    else
                    {
                        dtScaleTable.Clear();
                        ClsControlPack.CopyDataToDatatable(ref dtScaleTable, ref dataTable2, true);
                        ClsControlPack.RefreshAndAutoSize(beltActualGrid);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("实绩查询失败，请联系技术中心！" + ex.Message);
                return;
            }
        }
        //实绩新增
        private void AddScalePrediction() {
            RESTfulResult<string> rm = BeltActualService.doAdd(findFromInfo(1));
            if (rm.Succeed)
            {
                MessageBox.Show("新增实绩成功");
                QueryScaleActualinfo();
                return;
            }
            else
            {
                MessageBox.Show("新增实绩失败，请联系技术中心！" + rm.Message);
                return;
            }
        }
        //实绩修改
        private void UpdateScalePrediction()
        {
            try
            {
                if (!checkIsNull("from"))
                {
                    MessageBox.Show("请选择需要修改的实绩！");
                    return;
                }
                RESTfulResult<string> rm = BeltActualService.doUpdateWf(findFromInfo(2));
                if (rm.Succeed)
                {
                    MessageBox.Show("实绩修改成功");
                    QueryScaleActualinfo();
                    return;
                }
                else
                {
                    MessageBox.Show("实绩修改失败，请联系技术中心！" + rm.Message);
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("实绩修改异常！" + ex.Message);
                return;
            }
        }
        //实绩删除
        private void DeleteAndRecoverScaleActual(int no)
        {
            try
            {
                List<MeterWorkBeltActual> list = new List<MeterWorkBeltActual>();//实绩实体
                string flag = "";
                //获取已选择的列
                List<UltraGridRow> uGrid = GridHelper.UltraGridGetChooseRows(beltActualGrid, "UNCK");
                if (!checkIsNull("check",uGrid.Count)) {
                    MessageBox.Show("请勾选需要操作的实绩！");
                    return;
                }
                if (no == 1)
                {
                    foreach (UltraGridRow ugr in uGrid)
                    {
                        flag = ugr.Cells["valueFlag"].Value.ToString();
                        if (flag == "0")
                        {
                            MessageBox.Show("该实绩已是无效，不允许删除！");
                            return;
                        }
                        list.Add(new MeterWorkBeltActual { valueFlag = "0", actualNo = ugr.Cells["actualNo"].Value.ToString() });
                    }
                    RESTfulResult<int> rm = BeltActualService.doUpdateFlags(list);
                    if (rm.Succeed)
                    {
                        MessageBox.Show("实绩删除成功");
                        QueryScaleActualinfo();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("实绩删除失败，请联系技术中心！" + rm.Message);
                        return;
                    }
                }
                else if(no==2){
                    foreach (UltraGridRow ugr in uGrid)
                    {
                        flag = ugr.Cells["valueFlag"].Value.ToString();
                        if (flag != "0")
                        {
                            MessageBox.Show("不是无效的实绩不允许还原！");
                            return;
                        }
                        list.Add(new MeterWorkBeltActual { valueFlag = "1", actualNo = ugr.Cells["actualNo"].Value.ToString() });
                    }
                    RESTfulResult<int> rm = BeltActualService.doUpdateFlags(list);
                    if (rm.Succeed)
                    {
                        MessageBox.Show("实绩还原成功");
                        QueryScaleActualinfo();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("实绩还原失败，请联系技术中心！" + rm.Message);
                        return;
                    }
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("实绩删除还原异常！" + ex.Message);
                return;
            }
        }
     
        //审核
        private void ApproveScaleActual(int no) {
            try
            {
                List<MeterWorkBeltActual> list = new List<MeterWorkBeltActual>();//实绩实体
                string flag = "";
                //获取已选择的列
                List<UltraGridRow> uGrid = GridHelper.UltraGridGetChooseRows(beltActualGrid, "UNCK");
                if (!checkIsNull("check", uGrid.Count))
                {
                    MessageBox.Show("请勾选需要操作的实绩！");
                    return;
                }
                if (no == 1) {
                    foreach (UltraGridRow ugr in uGrid)
                    {
                        flag = ugr.Cells["checkFlag"].Value.ToString();
                        if (flag != "0")
                        {
                            MessageBox.Show("不是未审核的实绩不允许审核！");
                            return;
                        }
                        list.Add(new MeterWorkBeltActual { checkFlag = "1", actualNo = ugr.Cells["actualNo"].Value.ToString() });
                    }
                    RESTfulResult<int> rm = BeltActualService.doUpdateCheckFlags(list);
                    if (rm.Succeed)
                    {
                        MessageBox.Show("审核成功！");
                        QueryScaleActualinfo();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("审核失败，请联系技术中心！" + rm.Message);
                        return;
                    }
                } else if (no==2) {
                    foreach (UltraGridRow ugr in uGrid)
                    {
                        flag = ugr.Cells["checkFlag"].Value.ToString();
                        if (flag != "1")
                        {
                            MessageBox.Show("不是审核的实绩不允许取消审核！");
                            return;
                        }
                        list.Add(new MeterWorkBeltActual { checkFlag = "0", actualNo = ugr.Cells["actualNo"].Value.ToString() });
                    }
                    RESTfulResult<int> rm = BeltActualService.doUpdateCheckFlags(list);
                    if (rm.Succeed)
                    {
                        MessageBox.Show("取消审核成功！");
                        QueryScaleActualinfo();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("取消审核失败，请联系技术中心！" + rm.Message);
                        return;
                    }
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show("审核异常！" + ex.Message);
                return;
            }
        }
       
        //导出
        private void ExporterScaleActual()
        {
            string str = Interaction.InputBox("请输入要导出的文件名", "提示", "", 100, 100);
            string pqath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            this.ultraGridExcelExporter1.Export(this.beltActualGrid, pqath + "\\" + str + ".xls");
            MessageBox.Show("导出成功，请查看桌面！是否有[" + str + ".xls]表格");
        }
        #endregion

        #region 公共方法区
        //初始化加载
        private void frmBeltScaleActualinfo_Load(object sender, EventArgs e)
        {
            ScaleName.SelectedIndex = -1;
            userinfo = ((ST_MainForm)(this.MdiParent)).AppUser;
            //设置grid除了选择列 其余不可编辑
            GridHelper.SetExcludeColumnsActive(beltActualGrid.DisplayLayout.Bands[0], "UNCK");
            userId = ((ST_MainForm)(this.MdiParent)).UserID;
            userName = ((ST_MainForm)(this.MdiParent)).UserName;
            dtStartTime.Value = Convert.ToDateTime((DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00"));
            dtEndTime.Value = Convert.ToDateTime((DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59")); 

            DataTable dt = new DataTable();
            dt.Columns.Add("TEXT");
            dt.Columns.Add("VALUE");
            dt.Rows.Add("-1", "全部");
            dt.Rows.Add("0", "无效");
            dt.Rows.Add("1", "有效");
            valueToCombo(dt, cmbState);
            this.cmbState.SelectedIndex = -1;
            
            DataTable dt2 = new DataTable();
            dt2.Columns.Add("TEXT");
            dt2.Columns.Add("VALUE");
            dt2.Rows.Add("0", "开始时间");
            dt2.Rows.Add("1", "结束时间");
            dt2.Rows.Add("2", "发布时间");
            valueToCombo(dt2, cbDateFlag);
            this.cbDateFlag.SelectedIndex = 0;


            ValueList vlistFlag3 = new ValueList();
            vlistFlag3.ValueListItems.Add("0", "无效");
            vlistFlag3.ValueListItems.Add("1", "有效");
            this.beltActualGrid.DisplayLayout.Bands[0].Columns["valueFlag"].ValueList = vlistFlag3;

            ValueList vlistFlag4 = new ValueList();
            vlistFlag4.ValueListItems.Add("0", "未审核");
            vlistFlag4.ValueListItems.Add("1", "已审核");
            this.beltActualGrid.DisplayLayout.Bands[0].Columns["checkFlag"].ValueList = vlistFlag4;

            InitFromLoad();//加载物料
            InitPntInfo();//加载计量点
            QueryScaleActualinfo();
        }
        //下拉框控件自定义option
        public static void valueToCombo(DataTable source, UltraComboEditor cbb)
        {
            cbb.DataSource = source;
            cbb.DisplayMember = "VALUE";
            cbb.ValueMember = "TEXT";
        }
        //下拉框控件自定义option
        public static void valueToCombo1(DataTable source, ComboBox cbb)
        {
            cbb.DataSource = source;
            cbb.DisplayMember = "VALUE";
            cbb.ValueMember = "TEXT";
        }
        //控件初始化加载
        private void InitFromLoad()
        {
            try
            {
                RESTfulResult<List<MeterBaseMatterInfo>> rmx = meterBaseMatterInfo.doQueryListLike(new MeterBaseMatterInfo { validFlag = "1", pageNum = 1, pageSize = 9999 });
                RESTfulResult<List<MeterBaseCustomerSupplier>> rmx2 = customerSupplierService.doQuery(new MeterBaseCustomerSupplier { validFlag = "1" });
               

                if (rmx.Succeed && rmx.Data != null && rmx.Data.Count > 0)
                {
                    dtMaterial = rmx.Data.ListToDataTable<MeterBaseMatterInfo>();
                    dtMaterial2 = dtMaterial.Copy();
                }
                if (dtMaterial != null)
                {
                    DataRow d1 = dtMaterial.NewRow();
                    d1["matterName"] = "全部";
                    d1["matterNo"] = "0";
                    dtMaterial.Rows.InsertAt(d1, 0);

                    cmMatName.DataSource = dtMaterial;
                    cmMatName.DisplayMember = "matterName";
                    cmMatName.ValueMember = "matterNo";

                    cmMatname_1.DataSource = dtMaterial2;
                    cmMatname_1.DisplayMember = "matterName";
                    cmMatname_1.ValueMember = "matterNo";
                    cmMatname_1.SelectedIndex = -1;
                }
                if (rmx2.Succeed && rmx2.Data != null && rmx2.Data.Count > 0)
                {
                    dtcustomerSupplier = rmx2.Data.ListToDataTable<MeterBaseCustomerSupplier>();
                }
                if (dtcustomerSupplier != null)
                {
                    DataRow d1 = dtcustomerSupplier.NewRow();
                    d1["customerSupplierName"] = "全部";
                    d1["customerSupplierNo"] = "0";
                    dtcustomerSupplier.Rows.InsertAt(d1, 0);
                    cbfahuo.DataSource = dtcustomerSupplier;
                    cbfahuo.DisplayMember = "customerSupplierName";
                    cbfahuo.ValueMember = "customerSupplierNo";

                    cbfahuo_1.DataSource = dtcustomerSupplier.Copy();
                    cbfahuo_1.DisplayMember = "customerSupplierName";
                    cbfahuo_1.ValueMember = "customerSupplierNo";
                    cbfahuo_1.SelectedIndex = -1;

                    DataTable dt2 = new DataTable();
                    dt2.Columns.Add("TEXT");
                    dt2.Columns.Add("VALUE");
                    dt2.Rows.Add("0", "西区炼铁");
                    dt2.Rows.Add("1", "东区炼铁");
                    valueToCombo1(dt2, cbshouh);
                    valueToCombo1(dt2.Copy(), cbshouh_1);
                    this.cbshouh.SelectedIndex = -1;
                    this.cbshouh_1.SelectedIndex = -1;

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("初始化失败  " + ex.ToString());
            }
        }
        //计量点信息
        private void InitPntInfo() {
            MeterBaseSpotInfoService meterBaseSpotInfoService = new MeterBaseSpotInfoService();//计量点信息
            RESTfulResult<List<MeterBaseSpotInfo>> spo = meterBaseSpotInfoService.doQueryWf(new MeterBaseSpotInfo { validFlag = "1", spotTypeNo = "001002005" });
            if (spo.Succeed && spo.Data != null && spo.Data.Count > 0)
            {
                dtPoint = spo.Data.ListToDataTable<MeterBaseSpotInfo>();
            }
            if (dtPoint != null)
            {
                cbPntName.DataSource = dtPoint;
                cbPntName.DisplayMember = "baseSpotName";
                cbPntName.ValueMember = "baseSpotNo";
            }
            cbPntName.SelectedIndex = -1;

        }
        private bool checkIsNull(string str="", int count=0) {
            if (str == "from") {
                if (actualNoTxt.Text.ToString().Trim() == "")
                {
                    return false;
                }
            } else if (str =="check") {
                if (count<1)
                {
                    return false;
                }
            }
            return true;
        }
        //日期选择框
        private void checkDate_CheckedChanged(object sender, EventArgs e)
        {
            if (checkDate.Checked)
            {
                cbDateFlag.Enabled = true;
                dtStartTime.Enabled = true;
                dtEndTime.Enabled = true;
            }
            else
            {
                cbDateFlag.Enabled = false;
                dtStartTime.Enabled = false;
                dtEndTime.Enabled = false;
            }
        }
        //船号选择框
        private void ckShipNo_CheckedChanged(object sender, EventArgs e)
        {
            if (ckShipNo.Checked)
            {
                ShipnoTxt_1.Enabled = true;
            }
            else
            {
                ShipnoTxt_1.Enabled = false;
            }
        }
        private void checkGridCell(UltraGrid grid)
        {
            try
            {
                grid.UpdateData();
                List<UltraGridRow> row = GridHelper.SetAllColumnsCheckByCode(beltActualGrid, "actualNo", "UNCK", IsBatch);
                if (row.Count == 0)
                {
                    clearGridTable();
                    return;
                }
                //界面赋值
                UltraGridRow ugr = row[0];
                MeterWorkBeltActual beltActual = new MeterWorkBeltActual();//实绩实体
                if (ugr != null)
                {
                    beltActual.actualNo = ugr.Cells["actualNo"].Text.Trim(); //实绩编号
                    //beltActual.baseSpotNo = ugr.Cells["baseSpotNo"].Text.ToString();//计量点编码
                    beltActual.baseSpotName = ugr.Cells["baseSpotName"].Text.ToString();//计量点
                    beltActual.scaleName = ugr.Cells["scaleName"].Text.ToString();//AB秤
                    beltActual.createManName = ugr.Cells["createManName"].Text.ToString();//计量员
                    beltActual.overstock = ugr.Cells["overstock"].Text.ToString() == "" ? DateTime.Now : Convert.ToDateTime(ugr.Cells["overstock"].Text.ToString());//压港时间
                    beltActual.startTime = ugr.Cells["startTime"].Text.ToString() == "" ? DateTime.Now : Convert.ToDateTime(ugr.Cells["startTime"].Text.ToString());//开始时间
                    beltActual.endTime = ugr.Cells["endTime"].Text.ToString() == "" ? DateTime.Now : Convert.ToDateTime(ugr.Cells["endTime"].Text.ToString());//结束时间
                    beltActual.forwardingWeight = ugr.Cells["forwardingWeight"].Text.Trim() == "" ? 0 : Convert.ToDouble(ugr.Cells["forwardingWeight"].Text.Trim());//报港数量
                    beltActual.startWeight = ugr.Cells["startWeight"].Text.Trim() == "" ? 0 : Convert.ToDouble(ugr.Cells["startWeight"].Text.Trim());//开始重量
                    beltActual.endWeight = ugr.Cells["endWeight"].Text.Trim() == "" ? 0 : Convert.ToDouble(ugr.Cells["endWeight"].Text.Trim());//结束重量
                    beltActual.netWeight = ugr.Cells["netWeight"].Text.Trim() == "" ? 0 : Convert.ToDouble(ugr.Cells["netWeight"].Text.Trim());//结束重量
                    //beltActual.unloadWharf = ugr.Cells["unloadWharf"].Text.Trim();//卸货码头
                    beltActual.shipNo = ugr.Cells["shipNo"].Text.Trim();//船号
                    beltActual.newSupplier = ugr.Cells["newSupplier"].Text.Trim();//发货单位
                    beltActual.receivingUintName = ugr.Cells["receivingUintName"].Text.Trim(); //收货单位
                    beltActual.unloadSite = ugr.Cells["unloadSite"].Text.Trim(); //备注
                    //beltActual.forwardingUnitNo = ugr.Cells["forwardingUnitNo"].Text.Trim();//发货单位编号
                    //beltActual.receivingUintNo = ugr.Cells["receivingUintNo"].Text.Trim();//收货单位编号
                    beltActual.newMatName = ugr.Cells["newMatName"].Text.Trim();   //物料名称
                    beltActual.predictionNo = ugr.Cells["predictionNo"].Text.Trim();//计划
                    //beltActual.productNo = ugr.Cells["productNo"].Text.Trim();//物料编号
                    beltActual.orderNo = ugr.Cells["orderNo"].Text.Trim();//合同号
                    beltActual.newGg = ugr.Cells["newGg"].Text.Trim();//规格
                    beltActual.newMatClass = ugr.Cells["newMatClass"].Text.Trim();//物料类别
                    beltActual.newHlh = ugr.Cells["newHlh"].Text.Trim();//海轮号
                    autoAutoFill(beltActual);
                }
                else
                {
                    clearGridTable();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("checkGridCell方法处理异常：" + ex);
            }
        }
        //填充窗口表单
        private void autoAutoFill(MeterWorkBeltActual beltActual)
        {
            if (beltActual == null || string.IsNullOrEmpty(beltActual.actualNo))
            {
                return;
            }
            cbPntName.Text = beltActual.baseSpotName;//计量点
            cbfahuo_1.Text = beltActual.newSupplier;//发货单位
            cbshouh_1.Text = beltActual.receivingUintName;//收货单位
            cmMatname_1.Text = beltActual.newMatName;//物料名称
            shipnoTxt.Text = beltActual.shipNo;//船号
            actualNoTxt.Text = beltActual.actualNo;//实绩编号
            startWeightTxt.Text = beltActual.startWeight.ToString();//开始重量
            endWeight_Txt.Text = beltActual.endWeight.ToString();//结束重量
            netWeightTxt.Text = beltActual.netWeight.ToString();//净重
            meterStaffTxt.Text = beltActual.createManName;//计量员
            ScaleName.Text = beltActual.scaleName;//ab秤
            requiteWeightTxt.Text = beltActual.forwardingWeight.ToString();//发运重量
            startTime.Value = (DateTime)beltActual.startTime;//开始时间
            endTime.Value = (DateTime)beltActual.endTime;//开始时间
            predictionNo_Txt.Text = beltActual.predictionNo;
            newOrder_text.Text = beltActual.orderNo;//合同号
            newGg_text.Text = beltActual.newGg;//规格
            newMatClass_text.Text = beltActual.newMatClass;//物料类别
            newHlh_text.Text = beltActual.newHlh;//海轮号
            moteTxt.Text = beltActual.unloadSite.Contains("含焦粉")?beltActual.unloadSite.Replace("含焦粉",""): beltActual.unloadSite;
            
        }

        #region 单选按钮 和文本框控制
        private void Rbtn_AB_CheckedChanged(object sender, EventArgs e)
        {
            if (Rbtn_AB.Checked) {
                Rbtn_A.Checked = false;
                Rbtn_B.Checked = false;
            }
        }

        private void Rbtn_A_CheckedChanged(object sender, EventArgs e)
        {
            if (Rbtn_A.Checked)
            {
                Rbtn_AB.Checked = false;
                Rbtn_B.Checked = false;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (Rbtn_B.Checked)
            {
                Rbtn_AB.Checked = false;
                Rbtn_A.Checked = false;
            }
        }

        private void startWeightTxt_KeyPress(object sender, KeyPressEventArgs e)
        {
            int keyValue = (int)e.KeyChar;
            if ((keyValue >= 48 && keyValue <= 57) || keyValue == 8 || keyValue == 46)
            {
                if (sender != null && sender is TextBox && keyValue == 46)
                {
                    if (((TextBox)sender).Text.IndexOf(".") >= 0)
                        e.Handled = true;
                    else
                        e.Handled = false;
                }
                else
                    e.Handled = false;
            }
            else
                e.Handled = true;
        }

        private void endWeight_Txt_KeyPress(object sender, KeyPressEventArgs e)
        {
            int keyValue = (int)e.KeyChar;
            if ((keyValue >= 48 && keyValue <= 57) || keyValue == 8 || keyValue == 46)
            {
                if (sender != null && sender is TextBox && keyValue == 46)
                {
                    if (((TextBox)sender).Text.IndexOf(".") >= 0)
                        e.Handled = true;
                    else
                        e.Handled = false;
                }
                else
                    e.Handled = false;
            }
            else
                e.Handled = true;
        }

        private void netWeightTxt_KeyPress(object sender, KeyPressEventArgs e)
        {
            int keyValue = (int)e.KeyChar;
            if ((keyValue >= 48 && keyValue <= 57) || keyValue == 8 || keyValue == 46)
            {
                if (sender != null && sender is TextBox && keyValue == 46)
                {
                    if (((TextBox)sender).Text.IndexOf(".") >= 0)
                        e.Handled = true;
                    else
                        e.Handled = false;
                }
                else
                    e.Handled = false;
            }
            else
                e.Handled = true;
        }

        private void endWeight_Txt_TextChanged(object sender, EventArgs e)
        {
            this.netWeightTxt.Text = (Convert.ToDouble(endWeight_Txt.Text.ToString().Trim()) - Convert.ToDouble(startWeightTxt.Text.ToString().Trim())).ToString();
        }

        private void beltActualGrid_CellChange(object sender, CellEventArgs e)
        {
            if (e.Cell.Column.Key == "UNCK")
            {
                checkGridCell(beltActualGrid);
            }
        }
       
        private void clearGridTable() {
            cbPntName.Text = "";//计量点
            cbfahuo_1.Text = "";//发货单位
            cbshouh_1.Text = "";//收货单位
            cmMatname_1.Text = "";//物料名称
            shipnoTxt.Text = "";//船号
            actualNoTxt.Text = "";//实绩编号
            startWeightTxt.Text = "0";//开始重量
            endWeight_Txt.Text = "0";//结束重量
            netWeightTxt.Text = "0";//净重
            meterStaffTxt.Text = "";//计量员
            ScaleName.Text = "";//ab秤
            requiteWeightTxt.Text = "";//发运重量
            moteTxt.Text = "";
            predictionNo_Txt.Text = "";
            newOrder_text.Text = "";//合同号
            newGg_text.Text = "";//规格
            newMatClass_text.Text = "";//物料类别
            newHlh_text.Text = "";//海轮号
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                IsBatch = true;
            }
            else {
                IsBatch = false;
            }
        }
        #endregion

        //获取表单数据
        private MeterWorkBeltActual findFromInfo(int no)
        {
            MeterWorkBeltActual beltActual = new MeterWorkBeltActual();
            beltActual.baseSpotName= cbPntName.Text;//计量点
            beltActual.newSupplier = cbfahuo_1.Text;//发货单位
            beltActual.forwardingUnitNo = cbfahuo_1.SelectedValue.ToString();//发货单位编码
            beltActual.receivingUintName=cbshouh_1.Text;//收货单位
            beltActual.receivingUintNo=cbshouh_1.SelectedValue.ToString();//收货单位编码
            beltActual.newMatName = cmMatname_1.Text;//物料名称
            beltActual.shipNo= shipnoTxt.Text;//船号
            beltActual.actualNo= actualNoTxt.Text;//实绩编号
            beltActual.startWeight= Convert.ToDouble(startWeightTxt.Text.Trim());//开始重量
            beltActual.endWeight = Convert.ToDouble(endWeight_Txt.Text.Trim());//结束重量
            beltActual.netWeight = Convert.ToDouble(netWeightTxt.Text.Trim());//净重重量
            beltActual.createManName=meterStaffTxt.Text;//计量员
            beltActual.scaleName=ScaleName.Text;//ab秤
            beltActual.forwardingWeight= Convert.ToDouble(requiteWeightTxt.Text);//发运重量
            beltActual.startTime=startTime.Value;//开始时间
            beltActual.endTime=endTime.Value;//结束时间
            beltActual.unloadSite=moteTxt.Text;
            beltActual.predictionNo = predictionNo_Txt.Text.ToString().Trim();
            beltActual.orderNo = newOrder_text.Text.ToString().Trim();//合同号
            beltActual.newGg = newGg_text.Text.ToString().Trim();//规格
            beltActual.newMatClass = newMatClass_text.Text.ToString().Trim();//物料类别
            beltActual.newHlh = newHlh_text.Text.ToString().Trim();//海轮号
            if (no == 1)
            {
                beltActual.createManNo = userId;
                beltActual.createManName = userName;
                beltActual.meterClass = userinfo.userClass;//班级班组
                beltActual.meterGroup = userinfo.userGroup;
            }
            else {
                beltActual.updateManNo = userId;
                beltActual.updateManName = userName;
            }
            return beltActual;
        }
        #endregion
    }
}