private void otherDevSave(System.Collections.Generic.List <System.Collections.Hashtable> list)
 {
     foreach (System.Collections.Hashtable current in list)
     {
         string str_ip   = (string)current["ip"];
         string text     = (string)current["devNm"];
         string str_type = (string)current["type"];
         string text2    = (string)current["devID"];
         int    i_usage  = 0;
         System.Collections.Generic.List <Branch> list2      = new System.Collections.Generic.List <Branch>();
         System.Collections.Generic.List <string> branchList = InSnergyService.GetBranchList(text2);
         foreach (string current2 in branchList)
         {
             System.Collections.Generic.List <SubMeter> list3 = new System.Collections.Generic.List <SubMeter>();
             Branch item = new Branch(text2, current2, "", "", list3);
             list2.Add(item);
             System.Collections.Generic.List <string> meterList = InSnergyService.GetMeterList(text2, current2);
             foreach (string current3 in meterList)
             {
                 SubMeter item2 = new SubMeter(text2, current2, current3, "", 0f, i_usage);
                 list3.Add(item2);
             }
         }
         InSnergyGateway inSnergyGateway = new InSnergyGateway(text2, text, str_type, str_ip, list2);
         if (inSnergyGateway.Insert() > 0)
         {
             string valuePair = ValuePairs.getValuePair("Username");
             if (!string.IsNullOrEmpty(valuePair))
             {
                 LogAPI.writeEventLog("0432010", new string[]
                 {
                     text,
                     valuePair
                 });
             }
             else
             {
                 LogAPI.writeEventLog("0432010", new string[]
                 {
                     text
                 });
             }
             InSnergyService.Manage(text2);
         }
     }
 }
        private void butSaveISGDev_Click(object sender, System.EventArgs e)
        {
            bool flag = true;

            for (int i = 0; i < this.dgvSubMeters.Rows.Count; i++)
            {
                DataGridViewRow       dataGridViewRow       = this.dgvSubMeters.Rows[i];
                DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
                try
                {
                    string value = dataGridViewRow.Cells[7].Value.ToString();
                    System.Convert.ToSingle(value);
                    dataGridViewCellStyle.BackColor = Color.WhiteSmoke;
                    dataGridViewRow.Cells[7].Style  = dataGridViewCellStyle;
                }
                catch (System.Exception)
                {
                    dataGridViewCellStyle.BackColor = Color.Red;
                    dataGridViewRow.Cells[7].Style  = dataGridViewCellStyle;
                    this.dgvSubMeters.CurrentCell   = dataGridViewRow.Cells[7];
                    this.dgvSubMeters.BeginEdit(true);
                    flag = false;
                }
            }
            if (!flag)
            {
                EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Comm_invalidNumber, new string[0]));
                return;
            }
            InSnergyGateway gateWaybyBID = InSnergyGateway.GetGateWaybyBID(this.m_branchID);
            Branch          branch       = gateWaybyBID.BranchList[0];
            string          branchName   = branch.BranchName;

            branch.BranchName = this.tbBranchNm.Text;
            branch.Location   = this.tbBranchLoct.Text;
            for (int j = 0; j < this.dgvSubMeters.Rows.Count; j++)
            {
                DataGridViewRow dataGridViewRow = this.dgvSubMeters.Rows[j];
                string          value           = dataGridViewRow.Cells[7].Value.ToString();
                string          text            = dataGridViewRow.Cells[8].Value.ToString();
                string          value2          = dataGridViewRow.Cells[11].Value.ToString();
                for (int k = 0; k < branch.SubMeterCount; k++)
                {
                    SubMeter subMeter = branch.SubMeterList[k];
                    if (subMeter.SubmeterID.Equals(value2))
                    {
                        subMeter.Capacity = System.Convert.ToSingle(value);
                        int electricityUsage;
                        if (text.Equals("IT Power"))
                        {
                            electricityUsage = 1;
                        }
                        else
                        {
                            if (text.Equals("Non IT Power"))
                            {
                                electricityUsage = 2;
                            }
                            else
                            {
                                electricityUsage = 0;
                            }
                        }
                        subMeter.ElectricityUsage = electricityUsage;
                    }
                }
            }
            int num = branch.Save();

            if (num < 0)
            {
                EcoMessageBox.ShowError(EcoLanguage.getMsg(LangRes.Dev_ThresholdFail, new string[0]));
                return;
            }
            string valuePair = ValuePairs.getValuePair("Username");

            if (!string.IsNullOrEmpty(valuePair))
            {
                LogAPI.writeEventLog("0432013", new string[]
                {
                    branch.BranchName,
                    gateWaybyBID.GatewayName,
                    valuePair
                });
            }
            else
            {
                LogAPI.writeEventLog("0432013", new string[]
                {
                    branch.BranchName,
                    gateWaybyBID.GatewayName
                });
            }
            if (!branchName.Equals(branch.BranchName))
            {
                this.changeTreeSelect(this.m_gatewayID + ":" + this.m_branchID);
            }
            EcoMessageBox.ShowInfo(EcoLanguage.getMsg(LangRes.Dev_ThresholdSucc, new string[0]));
        }