public void Calc_Operation()
        {
            Sub_Account  = new SubAccountManul();
            Khazna_Moved = new KhznaMovedManul();
            float  KhaznaStartBalance = float.Parse(Sub_Account.GetSubAccount_ByID(int.Parse(KhaznaDropID.SelectedValue)).ElementAtOrDefault(0).ABalance.ToString());
            double MonyIn, MonyOut = 0;
            List <KhznaMovedManul> Khazna_Moved_List = new List <KhznaMovedManul>();

            Khazna_Moved_List = Khazna_Moved.GetAllKhznaMoved();
            Treasury_List     = new List <Treasury>();
            String operationTypeN = "";

            sum = KhaznaStartBalance;
            int counter = 0;

            foreach (var operation in Khazna_Moved_List)
            {
                if (operation.state == false)
                {
                    operationTypeN = "مستلم";

                    Treasury_List.Add(new Treasury()
                    {
                        OperationID     = operation.ID,
                        OperationType   = operationTypeN,
                        BalanceBefor    = sum,
                        BalanceAfter    = float.Parse(operation.Value.ToString()) + sum,
                        Credit_Movement = 0,
                        InDebt_Movement = float.Parse(operation.Value.ToString())
                    });
                    sum = sum + float.Parse(operation.Value.ToString());
                }
                else
                {
                    operationTypeN = "صرف";
                    float s1 = 0;

                    s1 = sum - float.Parse(operation.Value.ToString());
                    Treasury_List.Add(new Treasury()
                    {
                        OperationID     = operation.ID,
                        OperationType   = operationTypeN,
                        BalanceBefor    = sum,
                        BalanceAfter    = s1,
                        Credit_Movement = float.Parse(operation.Value.ToString()),
                        InDebt_Movement = 0
                    });
                    sum = s1;
                }

                //  sum += float.Parse(operation.Value.ToString());
                counter++;
            }

            TreasuryGrd.DataSource = Treasury_List;
            TreasuryGrd.DataBind();
        }
        public void Initialize_Page()
        {
            Sub_Account                 = new SubAccountManul();
            FromDateTxt.Text            = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day;
            ToDateTxt.Text              = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day;
            KhaznaDropID.DataSource     = Sub_Account.GetSubAccount_ByUpID(1103);
            KhaznaDropID.DataTextField  = "name";
            KhaznaDropID.DataValueField = "ID";
            KhaznaDropID.DataBind();

            TreasuryGrd.DataSource = null;
            TreasuryGrd.DataBind();
        }
 protected void Button3_Click(object sender, EventArgs e)
 {
     Response.Clear();
     Response.Buffer = true;
     Response.AddHeader("content-disposition", "attachment;filename=تقرير خزينة.xls");
     Response.Charset     = "";
     Response.ContentType = "application/vnd.ms-excel";
     {
         using (StringWriter sw = new StringWriter())
         {
             HtmlTextWriter hw = new HtmlTextWriter(sw);
             TreasuryGrd.RenderControl(hw);
             string style = "<style> .textmode { } </style>";
             Response.Write(style);
             Response.Output.Write(sw.ToString());
             Response.Flush();
             Response.End();
         }
     }
 }