예제 #1
0
 protected void btns_Click(object sender, EventArgs e)
 {
     lblmsg.Text = "";
     if (ddlbusiness.SelectedIndex > -1)
     {
         btnaddnewaccount0.Visible = true;
     }
     else
     {
         btnaddnewaccount0.Visible = false;
     }
     fillgrid();
     ModalPopupExtender122.Hide();
 }
    protected void btnapd_Click(object sender, EventArgs e)
    {
        int       Currentyearorg = 0;
        int       Currentyear    = 0;
        DataTable dtda           = (DataTable)select("select Report_Period_Id,Convert(nvarchar,StartDate,101) as StartDate, Convert(nvarchar,EndDate,101) as EndDate from [ReportPeriod] where Compid = '" + Session["comid"] + "' and Whid='" + ddlbus.SelectedValue + "' and Active='1' ");

        if (dtda.Rows.Count > 0)
        {
            DataTable dtdaopb = new DataTable();
            dtdaopb = (DataTable)select("select top(1)Report_Period_Id from [ReportPeriod] where ReportPeriod.Report_Period_Id<'" + dtda.Rows[0]["Report_Period_Id"] + "' and  Whid='" + ddlbus.SelectedValue + "'  order by Report_Period_Id Desc");
            if (dtdaopb.Rows.Count > 0)
            {
                string     inse = "Insert into Report_period_confirm(Report_Period_Id,conform)values('" + dtda.Rows[0]["Report_Period_Id"] + "','1')";
                SqlCommand cmd  = new SqlCommand(inse, con);
                if (con.State.ToString() != "Open")
                {
                    con.Open();
                }
                cmd.ExecuteNonQuery();
                con.Close();
                Currentyear    = Convert.ToInt32(ddlacyear.SelectedItem.Text) + 1;
                Currentyearorg = DateTime.Now.Year + 1;
                int        yem   = Convert.ToInt32(ddlacyear.SelectedItem.Text) + 1;
                string     yname = ddlacyear.SelectedItem.Text + " TO " + yem.ToString();
                string     upd   = "Update ReportPeriod set Name='" + yname + "',StartDate='" + Convert.ToDateTime(lblfysdate.Text) + "',EndDate='" + Convert.ToDateTime(lblfyedate.Text) + "',FistStartDate='" + Convert.ToDateTime(lblfysdate.Text) + "' where Report_Period_Id='" + dtda.Rows[0]["Report_Period_Id"] + "'";
                SqlCommand cmd1  = new SqlCommand(upd, con);
                if (con.State.ToString() != "Open")
                {
                    con.Open();
                }
                cmd1.ExecuteNonQuery();
                con.Close();


                int        yem1   = Convert.ToInt32(ddlacyear.SelectedItem.Text) - 1;
                string     yname1 = yem1.ToString() + " TO " + ddlacyear.SelectedItem.Text;
                string     upd1   = "Update ReportPeriod set Name='" + yname1 + "',StartDate='" + Convert.ToDateTime(lblfysdate.Text).AddYears(-1).ToString() + "',EndDate='" + Convert.ToDateTime(lblfyedate.Text).AddYears(-1).ToString() + "',FistStartDate='" + Convert.ToDateTime(lblfysdate.Text) + "' where Report_Period_Id='" + dtdaopb.Rows[0]["Report_Period_Id"] + "'";
                SqlCommand cmd11  = new SqlCommand(upd1, con);
                if (con.State.ToString() != "Open")
                {
                    con.Open();
                }
                cmd11.ExecuteNonQuery();
                con.Close();
                int k = 1;
                for (int i = Currentyear; i < Currentyearorg; i++)
                {
                    DateTime   fye    = Convert.ToDateTime(lblfysdate.Text).AddYears(k);
                    DateTime   eye    = Convert.ToDateTime(lblfyedate.Text).AddYears(k);
                    int        sy     = Convert.ToInt32(ddlacyear.SelectedItem.Text) + k;
                    int        ey     = Convert.ToInt32(ddlacyear.SelectedItem.Text) + (k + 1);
                    string     nam    = sy.ToString() + " TO " + ey.ToString();
                    SqlCommand cmdtr2 = new SqlCommand("Insert into ReportPeriod(Name,StartDate,EndDate,FistStartDate,Active,Compid,Whid)Values('" + nam + "','" + fye + "','" + eye + "','" + fye + "','0','" + Session["Comid"] + "','" + ddlbus.SelectedValue + "') ", con);

                    if (con.State.ToString() != "Open")
                    {
                        con.Open();
                    }
                    cmdtr2.ExecuteNonQuery();
                    con.Close();
                    k += 1;
                    SqlCommand cmsa = new SqlCommand("SELECT max(Report_Period_Id) from ReportPeriod where Compid='" + Session["comid"] + "' and Whid='" + ddlbus.SelectedValue + "'", con);
                    con.Open();
                    object rig = cmsa.ExecuteScalar();
                    con.Close();
                    string         str5t1      = "select Id from AccountMaster where Whid='" + ddlbus.SelectedValue + "'";
                    SqlCommand     cmd32t1     = new SqlCommand(str5t1, con);
                    SqlDataAdapter adp15t1     = new SqlDataAdapter(cmd32t1);
                    DataTable      dtlogin14t1 = new DataTable();
                    adp15t1.Fill(dtlogin14t1);
                    foreach (DataRow dr in dtlogin14t1.Rows)
                    {
                        SqlCommand cmdtr13 = new SqlCommand("Insert into AccountBalance(AccountMasterId,Balance,Report_Period_Id)Values('" + dr["Id"] + "','0','" + rig + "') ", con);

                        con.Open();
                        cmdtr13.ExecuteNonQuery();
                        con.Close();
                    }
                }
                contr(false);
                ModalPopupExtender122.Hide();
            }
        }
    }