Exemplo n.º 1
0
    protected void ASPxGridView1_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e)
    {
        try
        {
            string s = e.Parameters;
            if (s == "Cancle")
            {
                this.ASPxGridView1.CancelEdit();
                return;
            }
            ASPxTextBox  Id                  = ASPxGridView1.FindEditFormTemplateControl("txt_Oid") as ASPxTextBox;
            ASPxComboBox personId            = ASPxGridView1.FindEditFormTemplateControl("cmb_Person") as ASPxComboBox;
            Wilson.ORMapper.OPathQuery query = new Wilson.ORMapper.OPathQuery(typeof(HrPayroll), "Id='" + Id.Text + "'");
            HrPayroll payroll                = C2.Manager.ORManager.GetObject(query) as HrPayroll;

            bool action = false;

            if (SafeValue.SafeString(personId.Value, "0") == "0")
            {
                throw new Exception("Name not be null!!!");
                return;
            }
            if (payroll == null)
            {
                action  = true;
                payroll = new HrPayroll();
            }

            payroll.Person = SafeValue.SafeInt(personId.Value, 0);
            ASPxDateEdit fromDate = ASPxGridView1.FindEditFormTemplateControl("txt_FromDate") as ASPxDateEdit;
            payroll.FromDate = fromDate.Date;
            ASPxDateEdit toDate = ASPxGridView1.FindEditFormTemplateControl("txt_ToDate") as ASPxDateEdit;
            payroll.ToDate = toDate.Date;
            ASPxTextBox term = ASPxGridView1.FindEditFormTemplateControl("txt_Term") as ASPxTextBox;
            payroll.Term = term.Text;
            ASPxTextBox pic = ASPxGridView1.FindEditFormTemplateControl("txt_Pic") as ASPxTextBox;
            payroll.Pic = pic.Text;
            ASPxComboBox status = ASPxGridView1.FindEditFormTemplateControl("cmb_StatusCode") as ASPxComboBox;
            payroll.StatusCode = status.Text;
            ASPxMemo remark = ASPxGridView1.FindEditFormTemplateControl("txt_Remark") as ASPxMemo;
            payroll.Remark = remark.Text;

            if (action)
            {
                payroll.CreateBy       = HttpContext.Current.User.Identity.Name;
                payroll.CreateDateTime = DateTime.Now;
                Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Inserted);
                Manager.ORManager.PersistChanges(payroll);
            }
            else
            {
                payroll.UpdateBy       = HttpContext.Current.User.Identity.Name;
                payroll.UpdateDateTime = DateTime.Now;
                Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Updated);
                Manager.ORManager.PersistChanges(payroll);
            }

            Session["Payroll"] = "Id=" + payroll.Id;
            this.dsPayroll.FilterExpression = Session["Payroll"].ToString();
            if (this.ASPxGridView1.GetRow(0) != null)
            {
                this.ASPxGridView1.StartEdit(0);
            }
        }
        catch (Exception ex) { throw new Exception(ex.Message); }
    }
Exemplo n.º 2
0
    protected void ASPxGridView1_CustomDataCallback(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
    {
        ASPxTextBox Id = ASPxGridView1.FindEditFormTemplateControl("txt_Oid") as ASPxTextBox;
        string      s  = e.Parameters;

        string[] ar = s.Split('_');

        if (ar.Length >= 2)
        {
            if (ar[0].Equals("Printline"))
            {
                #region
                int       rowIndex = SafeValue.SafeInt(ar[1], -1);
                ASPxLabel lbl_Id   = this.ASPxGridView1.FindRowCellTemplateControl(rowIndex, null, "lbl_Id") as ASPxLabel;
                string    sql      = string.Format(@"select FromDate,ToDate,Person from Hr_Payroll where Id={0}", SafeValue.SafeInt(lbl_Id.Text, 0));
                DataTable dt       = ConnectSql.GetTab(sql);
                string    Person   = "";
                DateTime  FromDate = DateTime.Now;
                DateTime  ToDate   = DateTime.Now;
                if (dt.Rows.Count > 0)
                {
                    Person   = SafeValue.SafeString(dt.Rows[0]["Person"]);
                    FromDate = SafeValue.SafeDate(dt.Rows[0]["FromDate"], DateTime.Now);
                    ToDate   = SafeValue.SafeDate(dt.Rows[0]["ToDate"], DateTime.Now);
                }
                e.Result = FromDate + "," + ToDate + "," + lbl_Id.Text + "," + Person;
                #endregion
            }
            if (ar[0].Equals("Editline"))
            {
                #region
                int       rowIndex = SafeValue.SafeInt(ar[1], -1);
                ASPxLabel lbl_Id   = this.ASPxGridView1.FindRowCellTemplateControl(rowIndex, null, "lbl_Id") as ASPxLabel;
                e.Result = lbl_Id.Text;
                #endregion
            }
            if (ar[0].Equals("Deleteline"))
            {
                #region
                int       rowIndex = SafeValue.SafeInt(ar[1], -1);
                ASPxLabel lbl_Id   = this.ASPxGridView1.FindRowCellTemplateControl(rowIndex, null, "lbl_Id") as ASPxLabel;
                string    sql      = string.Format(@"delete from Hr_Payroll where Id='{0}'", SafeValue.SafeInt(lbl_Id.Text, 0));
                int       res      = ConnectSql_mb.ExecuteNonQuery(sql);
                if (res > 0)
                {
                    e.Result = "Success";
                }
                #endregion
            }
        }
        else
        {
            #region
            if (s == "Confirm")
            {
                string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Confirm' where StatusCode='Draft'");
                ConnectSql.ExecuteSql(update_sql);

                e.Result = "Success!";
            }
            if (s == "UnConfirm")
            {
                string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Draft' where Id={0}", SafeValue.SafeInt(Id.Text, 0));
                ConnectSql.ExecuteSql(update_sql);

                e.Result = "Success!";
            }
            if (s == "UnCancel")
            {
                string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Draft' where Id={0}", SafeValue.SafeInt(Id.Text, 0));
                ConnectSql.ExecuteSql(update_sql);

                e.Result = "Success!";
            }

            if (s == "Payroll")
            {
                string    value     = "Action Error! Pls check again";
                string    sql       = string.Format(@"select Person,sum(Amt) as TotalAmt,max(Remark) as Remark from Hr_Quote where (person in (select Id from hr_person where Status='EMPLOYEE')) group by Person");
                DataTable tab       = ConnectSql.GetTab(sql);
                int       fromYear  = txt_from.Date.Year;
                int       fromMonth = txt_from.Date.Month;
                string    name      = HttpContext.Current.User.Identity.Name;

                int    toYear  = txt_end.Date.Year;
                int    toMonth = txt_end.Date.Month;
                bool   result  = false;
                string from    = txt_from.Date.ToString("yyyy-MM-dd");
                string to      = txt_end.Date.ToString("yyyy-MM-dd");

                int month = toMonth - fromMonth;

                DateTime firstDayOfFromMonth = new DateTime(fromYear, fromMonth, 1);
                DateTime lastDayOfFromMonth  = new DateTime(fromYear, fromMonth, DateTime.DaysInMonth(fromYear, fromMonth));

                DateTime firstDayOfToMonth = new DateTime(toYear, toMonth, 1);
                DateTime lastDayOfToMonth  = new DateTime(toYear, toMonth, DateTime.DaysInMonth(toYear, toMonth));
                if (month < 2)
                {
                    for (int a = 0; a <= month; a++)
                    {
                        for (int i = 0; i < tab.Rows.Count; i++)
                        {
                            int    person  = SafeValue.SafeInt(tab.Rows[i]["Person"], 0);
                            string sql_pay = string.Format(@"select count(*) from Hr_Payroll where Person={0} and (FromDate>='{1}' and ToDate<='{2}')", person, firstDayOfFromMonth.ToString("yyyy-MM-dd"), lastDayOfFromMonth.ToString("yyyy-MM-dd"));
                            int    cnt     = SafeValue.SafeInt(ConnectSql.ExecuteScalar(sql_pay), 0);
                            if (cnt == 0)
                            {
                                #region From Date
                                decimal amt    = SafeValue.SafeDecimal(tab.Rows[i]["TotalAmt"]);
                                string  remark = SafeValue.SafeString(tab.Rows[i]["Remark"]);

                                HrPayroll payroll = new HrPayroll();
                                payroll.Person         = person;
                                payroll.FromDate       = firstDayOfFromMonth;
                                payroll.ToDate         = lastDayOfFromMonth;
                                payroll.StatusCode     = "Draft";
                                payroll.Term           = "";
                                payroll.Remark         = "";
                                payroll.Pic            = "";
                                payroll.CreateBy       = name;
                                payroll.CreateDateTime = DateTime.Now;
                                payroll.Amt            = amt;
                                payroll.AutoInd        = "Yes";

                                Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Inserted);
                                Manager.ORManager.PersistChanges(payroll);

                                sql = string.Format(@"select * from Hr_Quote where Person={0}  ", person);
                                DataTable tabDet = ConnectSql.GetTab(sql);
                                for (int j = 0; j < tabDet.Rows.Count; j++)
                                {
                                    string  code   = SafeValue.SafeString(tabDet.Rows[j]["PayItem"]);
                                    string  des    = SafeValue.SafeString(tabDet.Rows[j]["Remark"]);
                                    decimal payamt = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                    decimal before = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                    sql = string.Format(@"insert into Hr_PayrollDet(PayrollId,ChgCode,Description,Amt,CreateBy,CreateDateTime,Before) values({0},'{1}','{2}',{3},'{4}',getdate(),{3})", payroll.Id, code, des.Replace("'", ""), payamt, name);

                                    ConnectSql.ExecuteSql(sql);
                                }
                                auto_calculate(person, payroll.Id);
                                //InsertLeave(payroll.Id, person, from, to, name);
                                C2.HrPayroll.UpdateMaster(payroll.Id);
                                #endregion
                                result = true;
                            }
                            string sql_pay_to = string.Format(@"select count(*) from Hr_Payroll where Person={0} and (FromDate>='{1}' and ToDate<='{2}')", person, firstDayOfToMonth.ToString("yyyy-MM-dd"), lastDayOfToMonth.ToString("yyyy-MM-dd"));
                            int    cnt_to     = SafeValue.SafeInt(ConnectSql.ExecuteScalar(sql_pay_to), 0);
                            if (cnt_to == 0)
                            {
                                #region To Date
                                decimal amt    = SafeValue.SafeDecimal(tab.Rows[i]["TotalAmt"]);
                                string  remark = SafeValue.SafeString(tab.Rows[i]["Remark"]);

                                HrPayroll payroll = new HrPayroll();
                                payroll.Person         = person;
                                payroll.FromDate       = firstDayOfToMonth;
                                payroll.ToDate         = lastDayOfToMonth;
                                payroll.StatusCode     = "Draft";
                                payroll.Term           = "";
                                payroll.Remark         = "";
                                payroll.Pic            = "";
                                payroll.CreateBy       = name;
                                payroll.CreateDateTime = DateTime.Now;
                                payroll.Amt            = amt;
                                payroll.AutoInd        = "Yes";

                                Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Inserted);
                                Manager.ORManager.PersistChanges(payroll);

                                sql = string.Format(@"select * from Hr_Quote where Person={0} ", person);
                                DataTable tabDet = ConnectSql.GetTab(sql);
                                for (int j = 0; j < tabDet.Rows.Count; j++)
                                {
                                    string  code   = SafeValue.SafeString(tabDet.Rows[j]["PayItem"]);
                                    string  des    = SafeValue.SafeString(tabDet.Rows[j]["Remark"]);
                                    decimal payamt = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                    decimal before = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                    sql = string.Format(@"insert into Hr_PayrollDet(PayrollId,ChgCode,Description,Amt,CreateBy,CreateDateTime,Before) values({0},'{1}','{2}',{3},'{4}',getdate(),{3})", payroll.Id, code, des, payamt, name);

                                    ConnectSql.ExecuteSql(sql);
                                }
                                auto_calculate(person, payroll.Id);
                                InsertLeave(payroll.Id, person, from, to, name);
                                C2.HrPayroll.UpdateMaster(payroll.Id);


                                CalcCpf(payroll.Id);



                                #endregion
                                result = true;
                            }
                        }
                    }
                    if (result)
                    {
                        value = "Success!";
                        btn_Sch_Click(null, null);
                    }
                }
                e.Result = value;
            }
            #endregion
        }
    }
Exemplo n.º 3
0
    protected void ASPxGridView1_CustomDataCallback1(object sender, ASPxGridViewCustomDataCallbackEventArgs e)
    {
        ASPxTextBox Id = ASPxGridView1.FindEditFormTemplateControl("txt_Oid") as ASPxTextBox;
        string      s  = e.Parameters;

        if (s == "Confirm")
        {
            string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Confirm' where StatusCode='Draft'");
            ConnectSql.ExecuteSql(update_sql);

            e.Result = "Success!";
        }
        if (s == "UnConfirm")
        {
            string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Draft' where Id={0}", SafeValue.SafeInt(Id.Text, 0));
            ConnectSql.ExecuteSql(update_sql);

            e.Result = "Success!";
        }
        if (s == "UnCancel")
        {
            string update_sql = string.Format(@"update Hr_Payroll set StatusCode='Draft' where Id={0}", SafeValue.SafeInt(Id.Text, 0));
            ConnectSql.ExecuteSql(update_sql);

            e.Result = "Success!";
        }
        if (s == "Payroll")
        {
            string    sql       = string.Format(@"select Person,sum(Amt) as TotalAmt,max(Remark) as Remark from Hr_Quote group by Person");
            DataTable tab       = ConnectSql.GetTab(sql);
            int       fromYear  = txt_from.Date.Year;
            int       fromMonth = txt_from.Date.Month;
            string    name      = HttpContext.Current.User.Identity.Name;

            int    toYear  = txt_end.Date.Year;
            int    toMonth = txt_end.Date.Month;
            bool   result  = false;
            string from    = txt_from.Date.ToString("yyyy-MM-dd");
            string to      = txt_end.Date.ToString("yyyy-MM-dd");

            int month = toMonth - fromMonth;

            DateTime firstDayOfFromMonth = new DateTime(fromYear, fromMonth, 1);
            DateTime lastDayOfFromMonth  = new DateTime(fromYear, fromMonth, DateTime.DaysInMonth(fromYear, fromMonth));

            DateTime firstDayOfToMonth = new DateTime(toYear, toMonth, 1);
            DateTime lastDayOfToMonth  = new DateTime(toYear, toMonth, DateTime.DaysInMonth(toYear, toMonth));
            if (month < 2)
            {
                for (int a = 0; a <= month; a++)
                {
                    for (int i = 0; i < tab.Rows.Count; i++)
                    {
                        int    person  = SafeValue.SafeInt(tab.Rows[i]["Person"], 0);
                        string sql_pay = string.Format(@"select count(*) from Hr_Payroll where Person={0} and (FromDate>='{1}' and ToDate<='{2}')", person, firstDayOfFromMonth.ToString("yyyy-MM-dd"), lastDayOfFromMonth.ToString("yyyy-MM-dd"));
                        int    cnt     = SafeValue.SafeInt(ConnectSql.ExecuteScalar(sql_pay), 0);

                        string sql_pay_to = string.Format(@"select count(*) from Hr_Payroll where Person={0} and (FromDate>='{1}' and ToDate<='{2}')", person, firstDayOfToMonth.ToString("yyyy-MM-dd"), lastDayOfToMonth.ToString("yyyy-MM-dd"));
                        int    cnt_to     = SafeValue.SafeInt(ConnectSql.ExecuteScalar(sql_pay_to), 0);
                        if (cnt == 0)
                        {
                            #region From Date
                            decimal amt    = SafeValue.SafeDecimal(tab.Rows[i]["TotalAmt"]);
                            string  remark = SafeValue.SafeString(tab.Rows[i]["Remark"]);

                            HrPayroll payroll = new HrPayroll();
                            payroll.Person         = person;
                            payroll.FromDate       = firstDayOfFromMonth;
                            payroll.ToDate         = lastDayOfFromMonth;
                            payroll.StatusCode     = "Draft";
                            payroll.Term           = "";
                            payroll.Remark         = "";
                            payroll.Pic            = "";
                            payroll.CreateBy       = name;
                            payroll.CreateDateTime = DateTime.Now;
                            payroll.Amt            = amt;

                            Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Inserted);
                            Manager.ORManager.PersistChanges(payroll);

                            sql = string.Format(@"select * from Hr_Quote where Person={0}", person);
                            DataTable tabDet = ConnectSql.GetTab(sql);
                            for (int j = 0; j < tabDet.Rows.Count; j++)
                            {
                                string  code   = SafeValue.SafeString(tabDet.Rows[j]["PayItem"]);
                                string  des    = SafeValue.SafeString(tabDet.Rows[j]["Remark"]);
                                decimal payamt = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                decimal before = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                sql = string.Format(@"insert into Hr_PayrollDet(PayrollId,ChgCode,Description,Amt,CreateBy,CreateDateTime,Before) values({0},'{1}','{2}',{3},'{4}',getdate(),{3})", payroll.Id, code, des, payamt, name);

                                ConnectSql.ExecuteSql(sql);
                            }
                            #endregion
                            result = true;
                        }
                        else if (cnt_to == 0)
                        {
                            #region To Date
                            decimal amt    = SafeValue.SafeDecimal(tab.Rows[i]["TotalAmt"]);
                            string  remark = SafeValue.SafeString(tab.Rows[i]["Remark"]);

                            HrPayroll payroll = new HrPayroll();
                            payroll.Person         = person;
                            payroll.FromDate       = firstDayOfToMonth;
                            payroll.ToDate         = lastDayOfToMonth;
                            payroll.StatusCode     = "Draft";
                            payroll.Term           = "";
                            payroll.Remark         = "";
                            payroll.Pic            = "";
                            payroll.CreateBy       = name;
                            payroll.CreateDateTime = DateTime.Now;
                            payroll.Amt            = amt;

                            Manager.ORManager.StartTracking(payroll, Wilson.ORMapper.InitialState.Inserted);
                            Manager.ORManager.PersistChanges(payroll);

                            sql = string.Format(@"select * from Hr_Quote where Person={0}", person);
                            DataTable tabDet = ConnectSql.GetTab(sql);
                            for (int j = 0; j < tabDet.Rows.Count; j++)
                            {
                                string  code   = SafeValue.SafeString(tabDet.Rows[j]["PayItem"]);
                                string  des    = SafeValue.SafeString(tabDet.Rows[j]["Remark"]);
                                decimal payamt = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                decimal before = SafeValue.SafeDecimal(tabDet.Rows[j]["Amt"]);
                                sql = string.Format(@"insert into Hr_PayrollDet(PayrollId,ChgCode,Description,Amt,CreateBy,CreateDateTime,Before) values({0},'{1}','{2}',{3},'{4}',getdate(),{3})", payroll.Id, code, des, payamt, name);

                                ConnectSql.ExecuteSql(sql);
                            }
                            #endregion
                            result = true;
                        }
                        else
                        {
                            result   = false;
                            e.Result = "Had Created Payroll!No Need Again!";
                        }
                    }
                }
                if (result)
                {
                    e.Result = "Success!";
                }
            }
        }
    }