Beispiel #1
0
        private CEntitySoilStation GenerateSoilStationFromUI()
        {
            try
            {
                if (!AssertInputData())
                {
                    return(null);
                }
                // 读取界面数据,并构建一个站点实体类
                CEntitySoilStation soilStation = new CEntitySoilStation();
                soilStation.StationID   = textBox_StationID.Text.Trim(); //去掉空格
                soilStation.StationName = textBox_StationName.Text.Trim();
                soilStation.SubCenterID = CDBDataMgr.Instance.GetSubCenterByName(cmb_SubCenter.Text).SubCenterID;
                soilStation.StationType = CEnumHelper.UIStrToStationType(cmb_StationType.Text);

                //   soilStation.StrDeviceNumber=textBox_deviceNumber.Text.Trim();
                soilStation.VoltageMin = CStringFromatHelper.ConvertToNullableDecimal(textBox_Voltage.Text.ToString());
                soilStation.A10        = CStringFromatHelper.ConvertToNullableDecimal(textBox_10a.Text.ToString());
                soilStation.A20        = CStringFromatHelper.ConvertToNullableDecimal(textBox_20a.Text.ToString());
                soilStation.A30        = CStringFromatHelper.ConvertToNullableDecimal(textBox_30a.Text.ToString());
                soilStation.A40        = CStringFromatHelper.ConvertToNullableDecimal(textBox_40a.Text.ToString());
                soilStation.A60        = CStringFromatHelper.ConvertToNullableDecimal(textBox_60a.Text.ToString());

                soilStation.B10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10b.Text.ToString());
                soilStation.B20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20b.Text.ToString());
                soilStation.B30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30b.Text.ToString());
                soilStation.B40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40b.Text.ToString());
                soilStation.B60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60b.Text.ToString());

                soilStation.C10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10c.Text.ToString());
                soilStation.C20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20c.Text.ToString());
                soilStation.C30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30c.Text.ToString());
                soilStation.C40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40c.Text.ToString());
                soilStation.C60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60c.Text.ToString());

                soilStation.D10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10d.Text.ToString());
                soilStation.D20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20d.Text.ToString());
                soilStation.D30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30d.Text.ToString());
                soilStation.D40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40d.Text.ToString());
                soilStation.D60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60d.Text.ToString());

                soilStation.M10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10m.Text.ToString());
                soilStation.M20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20m.Text.ToString());
                soilStation.M30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30m.Text.ToString());
                soilStation.M40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40m.Text.ToString());
                soilStation.M60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60m.Text.ToString());

                soilStation.N10 = CStringFromatHelper.ConvertToNullableDecimal(textBox_10n.Text.ToString());
                soilStation.N20 = CStringFromatHelper.ConvertToNullableDecimal(textBox_20n.Text.ToString());
                soilStation.N30 = CStringFromatHelper.ConvertToNullableDecimal(textBox_30n.Text.ToString());
                soilStation.N40 = CStringFromatHelper.ConvertToNullableDecimal(textBox_40n.Text.ToString());
                soilStation.N60 = CStringFromatHelper.ConvertToNullableDecimal(textBox_60n.Text.ToString());

                if (!textBox_GSM.Text.Trim().Equals(""))
                {
                    string gsmNum = textBox_GSM.Text.Trim();
                    //  if (!CStringUtil.IsDigitStrWithSpecifyLength(gsmNum, 11))
                    // {
                    //  MessageBox.Show("GSM号码参数不合法,长度必须为11位,必须全部是数字!");
                    if (!CStringUtil.IsDigit(gsmNum))
                    {
                        MessageBox.Show("GSM号码参数不合法,必须全部是数字!");
                        return(null);
                    }
                    // 设置了GSM号码
                    soilStation.GSM = gsmNum;
                }

                if (!textBox_GPRS.Text.Trim().Equals(""))
                {
                    //GPRS号码
                    string gprsNum = textBox_GPRS.Text.Trim();
                    if (!CStringUtil.IsDigit(gprsNum))
                    {
                        MessageBox.Show("GPRS号码参数不合法,必须全部是数字!");
                        return(null);
                    }
                    soilStation.GPRS = gprsNum;
                }

                if (!textBox_Beidou.Text.Trim().Equals(""))
                {
                    string bdNum = textBox_Beidou.Text.Trim();
                    if (!CStringUtil.IsDigit(bdNum))
                    {
                        MessageBox.Show("北斗卫星终端号码参数不合法,必须全部是数字!");
                        return(null);
                    }
                    // 北斗卫星号码
                    soilStation.BDSatellite = bdNum;
                }

                if (!textBox_BeidouMember.Text.Trim().Equals(""))
                {
                    string bdNum = textBox_BeidouMember.Text.Trim();
                    if (!CStringUtil.IsDigit(bdNum))
                    {
                        MessageBox.Show("北斗卫星成员号码参数不合法,必须全部是数字!");
                        return(null);
                    }
                    // 北斗卫星号码
                    soilStation.BDMemberSatellite = bdNum;
                }

                soilStation.Maintran = comb_MainRoad.Text;
                soilStation.Subtran  = comb_PrepareRoad.Text;

                soilStation.Datapotocol    = comb_DataProtocol.Text;
                soilStation.Reportinterval = comb_Paragraph.Text;
                return(soilStation);
            }
            catch (Exception ex) { return(null); }
        }
        /// <summary>
        /// 获取更新过的数据,包括增加的用户记录
        /// </summary>
        private void GetUpdatedData()
        {
            try
            {
                // 标记为删除的就不需要添加的修改或者添加的分中心中了
                List <int> listEditRows = new List <int>();
                foreach (int item in base.m_listEditedRows)
                {
                    if (!m_listMaskedDeletedRows.Contains(item))
                    {
                        listEditRows.Add(item);
                    }
                }
                // 将去重后的项赋给编辑项
                base.m_listEditedRows = listEditRows;
                for (int i = 0; i < base.m_listEditedRows.Count; ++i)
                {
                    CEntitySoilStation soilStation = new CEntitySoilStation();
                    soilStation.StationID   = base.Rows[m_listEditedRows[i]].Cells[CS_StationId].Value.ToString();
                    soilStation.SubCenterID = CDBDataMgr.Instance.GetSubCenterByName(base.Rows[m_listEditedRows[i]].Cells[CS_StationSubcenter].Value.ToString()).SubCenterID;
                    // soilStation.SubCenterID = Int32.Parse(base.Rows[m_listEditedRows[i]].Cells[CS_StationSubcenter].Value.ToString());
                    soilStation.StationName = base.Rows[m_listEditedRows[i]].Cells[CS_StationName].Value.ToString();
                    soilStation.VoltageMin  = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_VoltageMin].Value.ToString());
                    soilStation.StationType = CEnumHelper.UIStrToStationType(base.Rows[m_listEditedRows[i]].Cells[CS_StationType].Value.ToString());


                    //  soilStation.StrDeviceNumber = base.Rows[m_listEditedRows[i]].Cells[CS_DeviceNumber].Value.ToString();
                    soilStation.A10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A10].Value.ToString());
                    soilStation.A20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A20].Value.ToString());
                    soilStation.A30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A30].Value.ToString());
                    soilStation.A40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A40].Value.ToString());
                    soilStation.A60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_A60].Value.ToString());

                    soilStation.B10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B10].Value.ToString());
                    soilStation.B20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B20].Value.ToString());
                    soilStation.B30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B30].Value.ToString());
                    soilStation.B40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B40].Value.ToString());
                    soilStation.B60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_B60].Value.ToString());

                    soilStation.C10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C10].Value.ToString());
                    soilStation.C20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C20].Value.ToString());
                    soilStation.C30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C30].Value.ToString());
                    soilStation.C40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C40].Value.ToString());
                    soilStation.C60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_C60].Value.ToString());

                    soilStation.D10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D10].Value.ToString());
                    soilStation.D20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D20].Value.ToString());
                    soilStation.D30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D30].Value.ToString());
                    soilStation.D40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D40].Value.ToString());
                    soilStation.D60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_D60].Value.ToString());

                    soilStation.M10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M10].Value.ToString());
                    soilStation.M20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M20].Value.ToString());
                    soilStation.M30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M30].Value.ToString());
                    soilStation.M40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M40].Value.ToString());
                    soilStation.M60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_M60].Value.ToString());

                    soilStation.N10 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N10].Value.ToString());
                    soilStation.N20 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N20].Value.ToString());
                    soilStation.N30 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N30].Value.ToString());
                    soilStation.N40 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N40].Value.ToString());
                    soilStation.N60 = CStringFromatHelper.ConvertToNullableDecimal(base.Rows[m_listEditedRows[i]].Cells[CS_N60].Value.ToString());

                    soilStation.GSM               = base.Rows[m_listEditedRows[i]].Cells[CS_Gsm].Value.ToString();
                    soilStation.GPRS              = base.Rows[m_listEditedRows[i]].Cells[CS_Gprs].Value.ToString();
                    soilStation.BDSatellite       = base.Rows[m_listEditedRows[i]].Cells[CS_BDsatellite].Value.ToString();
                    soilStation.BDMemberSatellite = base.Rows[m_listEditedRows[i]].Cells[CS_BDmember].Value.ToString();
                    soilStation.Maintran          = base.Rows[m_listEditedRows[i]].Cells[CS_Maintran].Value.ToString();
                    soilStation.Subtran           = base.Rows[m_listEditedRows[i]].Cells[CS_Subtran].Value.ToString();
                    soilStation.Datapotocol       = base.Rows[m_listEditedRows[i]].Cells[CS_Dataprotocol].Value.ToString();
                    soilStation.Reportinterval    = base.Rows[m_listEditedRows[i]].Cells[CS_Reportinterval].Value.ToString();

                    String preSoilStation = base.Rows[m_listEditedRows[i]].Cells[CS_StationId].Value.ToString();
                    if (preSoilStation == CS_PreStationId_None)
                    {
                        // 添加的新墒情站配置
                        m_listAddedSoilStation.Add(soilStation);
                    }
                    else
                    {
                        // 如果墒情站的测站id没有改变,那么是更新,如果发生了改变,那么需要先删除,然后添加新的
                        if (preSoilStation == soilStation.StationID)
                        {
                            m_listUpdatedSoilStation.Add(soilStation);
                        }
                        else
                        {
                            // 先删除之前的
                            m_listDeletedStation.Add(preSoilStation);
                            m_listAddedSoilStation.Add(soilStation); //然后再添加新的墒情站
                        }
                    }
                }
                m_listEditedRows.Clear();   //清空此次记录
            }
            catch (Exception ex)
            {
                this.Hide();
                MessageBox.Show("请在同一界面完成修改");
                this.Show();
            }
        }