/// <summary>
        /// �޸Ľ������
        /// </summary>
        public void UpdateObject()
        {
            //��ȡ�������
            PSP_VolumeBalance_Calc obj = FocusedObject;
            if (obj == null)
            {
                return;
            }
            PSP_VolumeBalance_Calc objtemp = new PSP_VolumeBalance_Calc ();
            objtemp.Title = obj.Title;
            objtemp.Type = obj.Type;
            //���������һ������
            PSP_VolumeBalance_Calc objCopy = new PSP_VolumeBalance_Calc();
            DataConverter.CopyTo<PSP_VolumeBalance_Calc>(obj, objCopy);

            //ִ���޸IJ���
            using (FrmPSP_VolumeBalance_CalcDialog dlg = new FrmPSP_VolumeBalance_CalcDialog())
            {
                dlg.Object = objCopy;   //�󶨸���
                dlg.Type = type;
                dlg.CtrTitle = ctrtitle;
                dlg.FormTitle = FormTitle;
                if (type == "1" && dy == "220")
                    dlg.editorRow2.Visible = true;
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            //�ø������½������
            DataConverter.CopyTo<PSP_VolumeBalance_Calc>(objCopy, obj);
            //ˢ�±��
            SaveSum();
            gridControl.RefreshDataSource();
            if (objtemp.Title!=obj.Title)
             if (obj.Type == "1")
            {

                IList<PSP_VolumeBalance_Calc> list = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeTitle", objtemp);
                foreach (PSP_VolumeBalance_Calc pvm in list)
                {
                    PSP_VolumeBalance_Calc pvc = new PSP_VolumeBalance_Calc();
                    pvc = pvm;
                    pvc.Title = obj.Title;

                    Services.BaseService.Update<PSP_VolumeBalance_Calc>(pvc);
                }
            }
        }
        /// <summary>
        /// ˢ�±���е�����
        /// </summary>
        /// <returns>ture:�ɹ�  false:ʧ��</returns>
        public bool RefreshData()
        {
            try
            {
                PSP_VolumeBalance_Calc pvc=new PSP_VolumeBalance_Calc();
                pvc.Type=type;
                pvc.Flag=flag;

                IList<PSP_VolumeBalance_Calc> list = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", pvc);
                this.gridControl.DataSource = list;
                SaveSum();
            }
            catch (Exception exc)
            {
                Debug.Fail(exc.Message);
                HandleException.TryCatch(exc);
                return false;
            }

            return true;
        }
        /// <summary>
        /// ɾ���������
        /// </summary>
        public void DeleteObject()
        {
            //��ȡ�������
            PSP_VolumeBalance_Calc obj = FocusedObject;
            if (obj == null)
            {
                return;
            }

            //����ȷ��
            if (MsgBox.ShowYesNo(Strings.SubmitDelete) != DialogResult.Yes)
            {
                return;
            }

            //ִ��ɾ������
            try
            {
                Services.BaseService.Delete<PSP_VolumeBalance_Calc>(obj);
            }
            catch (Exception exc)
            {
                Debug.Fail(exc.Message);
                HandleException.TryCatch(exc);
                return;
            }

            this.gridView.BeginUpdate();
            //��ס��ǰ����������
            int iOldHandle = this.gridView.FocusedRowHandle;
            //��������ɾ��
            ObjectList.Remove(obj);
            //ˢ�±��
            SaveSum();
            gridControl.RefreshDataSource();
            //�����µĽ���������
            GridHelper.FocuseRowAfterDelete(this.gridView, iOldHandle);
            this.gridView.EndUpdate();
            if (obj.Type == "1")
            {
                IList<PSP_VolumeBalance_Calc> list = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeTitle", obj);
                foreach (PSP_VolumeBalance_Calc pvm in list)
                {
                    PSP_VolumeBalance_Calc pvc = new PSP_VolumeBalance_Calc();
                    pvc = pvm;
                    pvc.Title = pvm.Title;

                    Services.BaseService.Delete<PSP_VolumeBalance_Calc>(pvc);
                    IList<PSP_VolumeBalance_Calc> list1 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", pvm);
                    deleSaveSum(list1, pvc.Flag);
                }
            }
        }
        /// <summary>
        /// ��Ӷ���
        /// </summary>
        public void AddObject()
        {
            //�����������Ƿ��Ѿ�����
            if (ObjectList == null)
            {
                return;
            }
            //�½�����
            PSP_VolumeBalance_Calc obj = new PSP_VolumeBalance_Calc();
            obj.Flag = flag;
            obj.Type = type;
            obj.Col1 = dy;
            obj.CreateTime = DateTime.Now;

            //ִ����Ӳ���
            using (FrmPSP_VolumeBalance_CalcDialog dlg = new FrmPSP_VolumeBalance_CalcDialog())
            {
                dlg.IsCreate = true;    //�����½���־
                dlg.Object = obj;
                dlg.Type = type;
                dlg.CtrTitle = ctrtitle;
                dlg.FormTitle = FormTitle;
                if (type == "1" && dy=="220")
                dlg.editorRow2.Visible = true;
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            //���¶�����뵽������
            ObjectList.Add(obj);
            SaveSum();
            //ˢ�±�񣬲��������ж�λ���¶����ϡ�
            gridControl.RefreshDataSource();
            GridHelper.FocuseRow(this.gridView, obj);
            if (obj.Type == "1")
            {
                PSP_VolumeBalance ob = new PSP_VolumeBalance();
                //ob.TypeID = dy;
                ob.UID = obj.Flag;
                //string s ="";
                IList<PSP_VolumeBalance> list = Services.BaseService.GetList<PSP_VolumeBalance>("SelectPSP_VolumeBalanceByKey", ob);
                if(list!=null)
                    if (list.Count == 1)
                    {

                        ob.Flag = list[0].Flag;
                        ob.TypeID = list[0].TypeID;
                        //s = obj.Flag;
                        list.Clear();
                        list = Services.BaseService.GetList<PSP_VolumeBalance>("SelectPSP_VolumeBalanceByTypeID", ob);
                        foreach (PSP_VolumeBalance pvm in list)
                        {
                            if (pvm.UID == ob.UID)
                                continue;
                            PSP_VolumeBalance_Calc pvc = new PSP_VolumeBalance_Calc();
                            pvc = obj;
                            pvc.Flag = pvm.UID;
                            pvc.UID = Guid.NewGuid().ToString();
                            pvc.Vol = 0;
                            pvc.Col2 = "";
                            Services.BaseService.Create<PSP_VolumeBalance_Calc>(pvc);
                        }
                    }
                RefreshData();
            }
        }
        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            PSP_VolumeBalance vol = new PSP_VolumeBalance();
            vol.TypeID = TypeID;
            vol.Flag = Flag;
            IList<PSP_VolumeBalance> listTypes = Services.BaseService.GetList<PSP_VolumeBalance>("SelectPSP_VolumeBalanceByTypeID", vol);
            FormChooseYears frm = new FormChooseYears();
            foreach (PSP_VolumeBalance year in listTypes)
                frm.ListYearsForChoose.Add(year.Year);

            frm.NoIncreaseRate = true;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                int k = 0;
                PSP_VolumeBalance vb = new PSP_VolumeBalance();
                vb.TypeID = TypeID;
                vb.Flag = Flag;
                IList<PSP_VolumeBalance> pspvb = Services.BaseService.GetList<PSP_VolumeBalance>("SelectPSP_VolumeBalanceByTypeID", vb);
                string str = "";
                PSP_VolumeBalance_Calc vbc = new PSP_VolumeBalance_Calc();
                try
                {
                    vbc.Flag = pspvb[0].UID;
                }
                catch { }
                vbc.Type = "1";
                IList<PSP_VolumeBalance_Calc> vbclist = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbc);

                DataTable dt = new DataTable();
                //dt.Columns.Add("Sort", typeof(int));
                dt.Columns.Add("序号", typeof(int));
                dt.Columns.Add("项目", typeof(string));

                int isort = 0;
                if (TypeID == "220")
                {
                    foreach (GridColumn i in ctrlPSP_VolumeBalance1.GridView.Columns)
                    {
                        if (i.Caption != "年度" && i.Caption != "小电厂需备用容量" && i.Caption != "外网供电" && i.FieldName != "S2" && i.FieldName != "S3")
                        {
                            if (i.FieldName == "S4")
                                i.Caption = "注:";
                            if (isort == 2)
                            {
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist)
                                {
                                    DataRow drow = dt.NewRow();

                                    //drow["序号"] = isort + 1;
                                    drow["项目"] = pspvbc.Title;
                                    dt.Rows.Add(drow);

                                    DataRow drow1 = dt.NewRow();
                                    drow1["项目"] = "注:";
                                    dt.Rows.Add(drow1);
                                }

                                isort++;
                                k = isort + vbclist.Count;
                            }
                            else if (isort == 10)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            else if (isort == 12)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            DataRow dr = dt.NewRow();
                            //dr["序号"] = isort + 1;
                            dr["项目"] = i.Caption;
                            //dr["Sort"] = isort + 1;
                            dt.Rows.Add(dr);
                            isort++;
                        }
                    }
                }
                if (TypeID == "35")
                {
                    foreach (GridColumn i in ctrlPSP_VolumeBalance1.GridView.Columns)
                    {
                        if (i.Caption != "年度" && i.Caption != "小电厂需备用容量" && i.Caption != "110kV及以下小电源直接供电负荷" && i.FieldName != "S3")
                        {
                            if(i.FieldName== "S2"|| i.FieldName == "S4")
                                i.Caption = "注:";
                            if (isort == 10)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            else if (isort == 12)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            DataRow dr = dt.NewRow();
                            //dr["序号"] = isort + 1;

                            dr["项目"] = i.Caption;
                            if (dr["项目"]!=null)
                            if (dr["项目"].ToString().Contains("(负荷同时率" + Ensureloadrate() + ")"))
                                 dr["项目"]=dr["项目"].ToString().Replace("(负荷同时率" + Ensureloadrate() + ")", "");
                            //dr["Sort"] = isort + 1;
                            dt.Rows.Add(dr);
                            isort++;
                        }
                    }
                }
                if (TypeID == "110")
                {
                    foreach (GridColumn i in ctrlPSP_VolumeBalance1.GridView.Columns)
                    {
                        if (i.Caption != "年度" && i.Caption != "小电厂需备用容量" )
                        {
                            if (i.FieldName == "S2" || i.FieldName == "S4" || i.FieldName == "S3")
                                i.Caption = "注:";
                            if (isort == 12)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            else if (isort == 14)
                            {
                                DataRow drow = dt.NewRow();
                                //drow["序号"] = isort + 1;
                                drow["项目"] = "注:";
                                dt.Rows.Add(drow);
                                isort++;
                            }
                            DataRow dr = dt.NewRow();
                            //dr["序号"] = isort + 1;
                            dr["项目"] = i.Caption;
                            //dr["Sort"] = isort + 1;
                            dt.Rows.Add(dr);
                            isort++;
                        }
                    }
                }
                isort = 1;
                foreach (System.Data.DataRow row in dt.Rows)
                {
                    row["序号"] = isort;
                    isort++;
                }

                foreach (ChoosedYears i in frm.ListChoosedYears)
                {
                    dt.Columns.Add(i.Year + "年", typeof(string));
                }
                //if (TypeID == "220")
                //{
                //    dt.Rows.RemoveAt(vbclist.Count + 14);
                //}
                foreach (ChoosedYears i in frm.ListChoosedYears)
                {

                    foreach (PSP_VolumeBalance balan in pspvb)
                    {
                        if (balan.Year == i.Year)
                        {
                            int j = 0;
                            dt.Rows[0][i.Year + "年"] = balan.L1;
                            dt.Rows[1][i.Year + "年"] = balan.L2;
                            PSP_VolumeBalance_Calc vbcalc = new PSP_VolumeBalance_Calc();
                            vbcalc.Flag = balan.UID;
                            vbcalc.Type = "1";
                            IList<PSP_VolumeBalance_Calc> vbclist1 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);

                            if (TypeID == "220")
                            {

                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist1)
                                {
                                    dt.Rows[j+2][i.Year + "年"] = pspvbc.Vol.ToString();
                                    j++;
                                    dt.Rows[j + 2][i.Year + "年"] = pspvbc.Col2.ToString();
                                    j++;
                                }
                                dt.Rows[j + 2][i.Year + "年"] = balan.L5;
                                dt.Rows[j + 3][i.Year + "年"] = balan.S4;
                                dt.Rows[j + 4][i.Year + "年"] = balan.L6;
                                dt.Rows[j + 5][i.Year + "年"] = balan.L7;
                                dt.Rows[j + 6][i.Year + "年"] = balan.L8;
                                dt.Rows[j + 7][i.Year + "年"] = balan.L9;
                                dt.Rows[j + 8][i.Year + "年"] = balan.L10;

                                str = "";
                                vbcalc.Type = "2";
                                IList<PSP_VolumeBalance_Calc> vbclist2 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist2)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist2[vbclist2.Count - 1].UID)
                                        str += ",";

                                }
                                dt.Rows[j + 9][i.Year + "年"] = str;
                                dt.Rows[j + 10][i.Year + "年"] = balan.L11;
                                str = "";
                                vbcalc.Type = "3";
                                IList<PSP_VolumeBalance_Calc> vbclist3 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist3)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist3[vbclist3.Count - 1].UID)
                                        str += ",";
                                }
                                dt.Rows[j + 11][i.Year + "年"] = str;
                                dt.Rows[j + 12][i.Year + "年"] = balan.L12;
                                dt.Rows[j + 13][i.Year + "年"] = balan.L13;
                                dt.Rows[j + 14][i.Year + "年"] = balan.L14;
                            }
                            else if (TypeID == "110")
                            {
                                //foreach (PSP_VolumeBalance_Calc pspvbc in vbclist1)
                                //{
                                //    str = "(" + pspvbc.Title + "," + pspvbc.LX1 + "," + pspvbc.LX2 + ")  " + str;
                                //}
                                dt.Rows[2][i.Year + "年"] = balan.S2;

                                dt.Rows[j + 3][i.Year + "年"] = balan.L4;
                                dt.Rows[j + 4][i.Year + "年"] = balan.S3;
                                dt.Rows[j + 5][i.Year + "年"] = balan.L5;
                                dt.Rows[j + 6][i.Year + "年"] = balan.S4;
                                dt.Rows[j + 7][i.Year + "年"] = balan.L6;
                                dt.Rows[j + 8][i.Year + "年"] = balan.L7;
                                dt.Rows[j + 9][i.Year + "年"] = balan.L8;
                                dt.Rows[j + 10][i.Year + "年"] = balan.L9;
                                dt.Rows[j + 11][i.Year + "年"] = balan.L10;

                                str = "";
                                vbcalc.Type = "2";
                                IList<PSP_VolumeBalance_Calc> vbclist2 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist2)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist2[vbclist2.Count - 1].UID)
                                        str += ",";

                                }
                                dt.Rows[j + 12][i.Year + "年"] = str;
                                dt.Rows[j + 13][i.Year + "年"] = balan.L11;

                                str = "";
                                vbcalc.Type = "3";
                                IList<PSP_VolumeBalance_Calc> vbclist3 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist3)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist3[vbclist3.Count - 1].UID)
                                        str += ",";
                                }
                                dt.Rows[j + 14][i.Year + "年"] = str;
                                dt.Rows[j + 15][i.Year + "年"] = balan.L12;
                                dt.Rows[j + 16][i.Year + "年"] = balan.L13;
                                dt.Rows[j + 17][i.Year + "年"] = balan.L14;
                            }
                            else if (TypeID == "35")
                            {
                                dt.Rows[j+2][i.Year + "年"] = balan.S2;
                                dt.Rows[j + 3][i.Year + "年"] = balan.L5;
                                dt.Rows[j + 4][i.Year + "年"] = balan.S4;
                                dt.Rows[j + 5][i.Year + "年"] = balan.L6;
                                dt.Rows[j + 6][i.Year + "年"] = balan.L7;
                                dt.Rows[j + 7][i.Year + "年"] = balan.L8;
                                dt.Rows[j + 8][i.Year + "年"] = balan.L9;
                                dt.Rows[j + 9][i.Year + "年"] = balan.L10;
                                //dt.Rows[j + 8][i.Year + "年"] = balan.L10;
                                str = "";
                                vbcalc.Type = "2";
                                IList<PSP_VolumeBalance_Calc> vbclist2 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist2)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist2[vbclist2.Count - 1].UID)
                                        str += ",";

                                }
                                dt.Rows[j + 10][i.Year + "年"] = str;
                                dt.Rows[j + 11][i.Year + "年"] = balan.L11;
                                str = "";
                                vbcalc.Type = "3";
                                IList<PSP_VolumeBalance_Calc> vbclist3 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", vbcalc);
                                foreach (PSP_VolumeBalance_Calc pspvbc in vbclist3)
                                {
                                    if (pspvbc.LX1 == "新建")
                                        str += pspvbc.LX1 + "" + pspvbc.Title + "" + pspvbc.LX2;
                                    else
                                        str += pspvbc.Title + "" + pspvbc.LX1 + "" + pspvbc.LX2;
                                    if (pspvbc.UID != vbclist3[vbclist3.Count - 1].UID)
                                        str += ",";
                                }
                                dt.Rows[j + 12][i.Year + "年"] = str;
                                dt.Rows[j + 13][i.Year + "年"] = balan.L12;
                                dt.Rows[j + 14][i.Year + "年"] = balan.L13;

                            }
                        }
                    }

                }

                FormPSP_VolumeBalance_Print fr = new FormPSP_VolumeBalance_Print();
                fr.GridDataTable = dt;
                //if (TypeID == "220")
                //{
                    fr.Text = this.Text;
                    fr.gridView1.GroupPanelText = this.Text;
                    fr.PRintRight = PrintRight;
                //}
                fr.ShowDialog();
            }
        }
        private void AddFuHe(PSP_VolumeBalance obj)
        {
            PSP_VolumeBalance pvc = new PSP_VolumeBalance();
            pvc.TypeID = type;
            pvc.Flag = flag;
            pvc.Year = EnsureBaseYear();
            IList<PSP_VolumeBalance> list = Services.BaseService.GetList<PSP_VolumeBalance>("SelectPSP_VolumeBalanceByTypeIDAndYear", pvc);
            if (list != null)
                if (list.Count == 1)
                {
                    PSP_VolumeBalance_Calc pvc2 = new PSP_VolumeBalance_Calc();
                    pvc2.Type ="1";
                    pvc2.Flag = list[0].UID;
                    IList<PSP_VolumeBalance_Calc> list2 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", pvc2);
                    PSP_VolumeBalance_Calc pvc3 = new PSP_VolumeBalance_Calc();
                    pvc3.Type = "1";
                    pvc3.Flag = obj.UID;
                    IList<PSP_VolumeBalance_Calc> list3 = Services.BaseService.GetList<PSP_VolumeBalance_Calc>("SelectPSP_VolumeBalance_CalcByTypeFlag", pvc3);
                    if (list2 != null)
                        if (list2.Count > 0)
                        {

                            foreach (PSP_VolumeBalance_Calc pvctemp in list2)
                            {
                                if (list3 != null)
                                    if (list3.Count == list2.Count)
                                        break;
                                PSP_VolumeBalance_Calc _obj = new PSP_VolumeBalance_Calc();
                                _obj = pvctemp;
                                _obj.Flag = obj.UID;
                                _obj.Vol = 0;
                                _obj.UID = Guid.NewGuid().ToString();

                                Services.BaseService.Create<PSP_VolumeBalance_Calc>(_obj);
                            }
                        }
                }
        }