Exemple #1
0
        private void tsbtsave_Click(object sender, EventArgs e)
        {
            string code   = txtma.Text;
            string name   = txtname.Text.Replace("'", "''");
            string branch = cbbranch.SelectedValue.ToString();
            //string branchID = gen.GetString("select BranchID from Branch where BranchCode='" + branch + "'");
            string dc    = txtdc.Text.Replace("'", "''");
            string mst   = txtmst.Text;
            string email = txtemail.Text;

            if (txtemail.Text != "")
            {
                try
                {
                    gen.GetString("select * from AccountingObject where AccountingObjectCode='" + txtemail.Text + "'");
                }
                catch
                {
                    XtraMessageBox.Show("Mã khách phụ không tồn tại vui lòng kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            string   tknh     = txttknh.Text;
            string   tnh      = txtnh.Text;
            string   chucdanh = txtcv.Text;
            string   cmnd     = txtcmnd.Text;
            DateTime ngaycap  = dtngaycap.Value;
            DateTime ngaysinh = dtborn.Value;
            string   noicap   = txtnoicap.Text;
            string   dtcq     = txtdtcq.Text;
            string   dtnr     = txtdtnr.Text;
            string   dtdd     = txtdtdd.Text;
            string   kh       = chbkh.Checked.ToString();
            string   ncc      = chncc.Checked.ToString();
            string   person   = "True";
            string   ntd      = chbntd.Checked.ToString();
            string   sex;
            string   hsl = txthsl.Text;

            if (txthsl.Text == "")
            {
                hsl = "0";
            }
            string gtgc = txtgtgc.Text.Replace(",", ".");

            if (rbfemale.Checked == true)
            {
                sex = "0";
            }
            else
            {
                sex = "1";
            }

            /*if (active == "1")
             * {
             *  string sql = "update AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',ContactSex='" + sex + "',
             *  EmployeeBirthday='" + ngaysinh + "',Address=N'" + dc + "',EmailAddress='" + email + "',BankAccount='" + tknh + "',BankName='" + tnh + "',
             *  CompanyTaxCode='" + mst + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactOfficeTel='" + dtcq + "',
             *  ContactHomeTel='" + dtnr + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',
             *  IssueBy='" + noicap + "',Inactive='" + ntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',FamilyDeductionAmount='" + gtgc + "',SalaryScaleID='" + hsl + "' where AccountingObjectID='" + role + "'";
             *  nhanvien.checknhanvien(active, txtma, txtname, sql, this);
             * }
             * else
             * {
             *  string nv = "True";
             *  string insu = "False";
             *  string labe = "False";
             *  //string sql = "insert into AccountingObject(AccountingObjectID,AccountingObjectCode,AccountingObjectName,BranchID,Address,EmailAddress,BankAccount,BankName,CompanyTaxCode,ContactTitle,ContactMobile,ContactOfficeTel,ContactHomeTel,IsPersonal,IdentificationNumber,IssueDate,IssueBy,Inactive,IsVendor,IsCustomer,IsEmployee,Insured,LabourUnionFee,FamilyDeductionAmount,AccountingObjectCategory,ContactSex,EmployeeBirthday,SalaryScaleID)  values(newid(),'" + code + "',N'" + name + "','" + branchID + "',N'" + dc + "','" + email + "','" + tknh + "','" + tnh + "','" + mst + "',N'" + chucdanh + "','" + dtdd + "','" + dtcq + "','" + dtnr + "','" + person + "','" + cmnd + "','" + ngaycap + "','" + noicap + "','" + ntd + "','" + ncc + "','" + kh + "','" + nv + "','" + insu + "','" + labe + "','" + gtgc + "','','" + sex + "','" + ngaysinh + "','" + hsl + "')";
             *  //nhanvien.checknhanvien(active, txtma, txtname, sql, this);
             * }*/
            AccountingObject data = new AccountingObject();

            if (active == "0")
            {
                data.AccountingObjectID = Guid.NewGuid();// tao guiid moi
            }
            else
            {
                data.AccountingObjectID = Guid.Parse(role);;
            }
            //data.ClientID = Globals.clientid;
            data.CompanyCode          = Globals.companycode;
            data.AccountingObjectCode = code;
            data.AccountingObjectName = name;
            data.BranchID             = Guid.Parse(branch);
            data.ContactSex           = Int32.Parse(sex);
            data.EmployeeBirthday     = ngaysinh;
            data.Address        = dc;
            data.EmailAddress   = email;
            data.BankAccount    = tknh;
            data.BankName       = tnh;
            data.CompanyTaxCode = mst;
            data.ContactTitle   = chucdanh;
            data.ContactMobile  = dtdd;

            data.ContactOfficeTel     = dtcq;
            data.ContactHomeTel       = dtnr;
            data.IsPersonal           = true;
            data.IsEmployee           = true;
            data.IdentificationNumber = cmnd;
            data.IssueDate            = ngaycap;
            data.ContactTitle         = chucdanh;
            data.IssueBy = noicap;

            data.Inactive   = chbntd.Checked;
            data.IsVendor   = chncc.Checked;
            data.IsCustomer = chbkh.Checked;
            try
            {
                data.FamilyDeductionAmount = Int32.Parse(gtgc);
                data.SalaryScaleID         = Int32.Parse(hsl);
            }
            catch
            {
            }



            var db = gen.GetNewEntity(); // khai bao new entity Framework
            {
                try
                {
                    if (active == "0")
                    {
                        db.AccountingObjects.Add(data);                    //insert
                    }
                    else
                    {
                        db.Entry(data).State = System.Data.Entity.EntityState.Modified;      // update
                    }
                    db.SaveChanges();
                    XtraMessageBox.Show("Submit successfully", "tsbtsave_Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //catch (DbUpdateException ex) // exception khac
                catch (DbUpdateConcurrencyException ex)     // exception khac
                {
                    XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message + active, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtSQL.Text = ex.Message + data + active;
                }
            }


            //lvpq.DataSource = data ;
            //txtSQL.Text = data.AccountingObjectID + data.AccountingObjectCode;
        }
Exemple #2
0
        private void tsbtsave_Click(object sender, EventArgs e)
        {
            string code   = txtma.Text;
            string name   = txttc.Text.Replace("'", "''");
            string branch = cbbranch.SelectedValue.ToString(); // branchID
            //string branchID = gen.GetString("select BranchID from Branch where BranchCode='" + branch + "'");
            string dc  = txtdc.Text.Replace("'", "''");
            string mst = txtmst.Text;
            string dt  = txtdt.Text;
            string fax = txtfax.Text;


            string web = txtwweb.Text;

            string email = txtemail.Text;

            if (txtemail.Text != "")
            {
                try
                {
                    gen.GetString("select * from AccountingObject where AccountingObjectCode='" + txtemail.Text + "'");
                }
                catch
                {
                    XtraMessageBox.Show("Mã khách phụ không tồn tại vui lòng kiểm tra lại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            string tknh = txttknh.Text;
            string tnh = txtnh.Text;
            string dg = txtdg.Text;
            string sntd = txtsntd.Text;
            string hn = txthn.Text;
            string tinh, quan;

            try
            {
                clsItem cls1 = (clsItem)cbprovince.SelectedItem;
                tinh = cls1.PstrValue;
            }
            catch { tinh = ""; }
            try
            {
                clsItem cls2 = (clsItem)cbdistrist.SelectedItem;
                quan = cls2.PstrValue;
            }
            catch { quan = ""; }
            string   tencon = txttencon.Text.Replace("'", "''");
            string   chucdanh = txtcdcon.Text;
            string   dccon = txtdccon.Text.Replace("'", "''");
            string   cmnd = txtscmnd.Text;
            DateTime ngaycap = dateTimePicker1.Value;
            string   noicap = txtnccon.Text;
            string   dtcq = txtdtcq.Text;
            string   dtnr = txtdtnr.Text;
            string   dtdd = txtdtdd.Text;
            string   emailcon = txtemailcon.Text;
            string   kh, ncc;

            if (rbkhncc.Checked == true)
            {
                kh  = "True";
                ncc = "True";
            }
            else
            {
                kh  = rbkh.Checked.ToString();
                ncc = rbncc.Checked.ToString();
            }

            string person = rbcn.Checked.ToString();
            string ntd    = chbntd.Checked.ToString();

            string khncc;

            if (rbkhncc.Checked == true)
            {
                khncc = "Khách hàng; Nhà cung cấp";
            }
            else
            {
                if (rbncc.Checked == true)
                {
                    khncc = "Nhà cung cấp";
                }
                else
                {
                    khncc = "Khách hàng";
                }
            }


            if (txtma.Text == "")
            {
                MessageBox.Show("Mã khách hàng, nhà cung cấp không được bỏ trống.", "HAMACO");
            }
            else if (txttc.Text == "")
            {
                MessageBox.Show("Tên khách hàng, nhà cung cấp không được bỏ trống.", "HAMACO");
            }

            /*else
             * {
             *  if (active == "1")
             *  {
             *      try
             *      {
             *          string kq = gen.GetString("select * from hamaco.dbo.AccountingObject where CompanyTaxCode='" + txtmst.Text + "' and CompanyTaxCode<>'' and AccountingObjectCode<>'" + txtma.Text + "'");
             *          MessageBox.Show("Mã số thuế này đã tồn tại. Vui lòng kiểm tra lại.", "Thông báo");
             *          return;
             *      }
             *      catch
             *      {
             *          gen.ExcuteNonquery("update hamaco.dbo.AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',Address=N'" + dc + "',Tel='" + dt + "',Fax='" + fax + "',EmailAddress='" + email + "',Website=N'" + web + "',BankAccount='" + tknh + "',BankName=N'" + tnh + "',CompanyTaxCode='" + mst + "',Description=N'" + dg + "',ContactName=N'" + tencon + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactEmail='" + emailcon + "',ContactOfficeTel='" + dtcq + "',ContactHomeTel='" + dtnr + "',ContactAddress=N'" + dccon + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',IssueBy=N'" + noicap + "',Inactive='" + ntd + "',DueTime='" + hn + "',MaximizeDebtAmount='" + sntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',Province='" + tinh + "',District='" + quan + "',AccountingObjectCategory=N'" + khncc + "',Village=N'" + cbprovince.Text + "' where AccountingObjectCode='" + txtma.Text + "'");
             *          gen.ExcuteNonquery("update hamaco_ta.dbo.AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',Address=N'" + dc + "',Tel='" + dt + "',Fax='" + fax + "',EmailAddress='" + email + "',Website=N'" + web + "',BankAccount='" + tknh + "',BankName=N'" + tnh + "',CompanyTaxCode='" + mst + "',Description=N'" + dg + "',ContactName=N'" + tencon + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactEmail='" + emailcon + "',ContactOfficeTel='" + dtcq + "',ContactHomeTel='" + dtnr + "',ContactAddress=N'" + dccon + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',IssueBy=N'" + noicap + "',Inactive='" + ntd + "',DueTime='" + hn + "',MaximizeDebtAmount='" + sntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',Province='" + tinh + "',District='" + quan + "',AccountingObjectCategory=N'" + khncc + "',Village=N'" + cbprovince.Text + "' where AccountingObjectCode='" + txtma.Text + "'");
             *          gen.ExcuteNonquery("update hamaco_tn.dbo.AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',Address=N'" + dc + "',Tel='" + dt + "',Fax='" + fax + "',EmailAddress='" + email + "',Website=N'" + web + "',BankAccount='" + tknh + "',BankName=N'" + tnh + "',CompanyTaxCode='" + mst + "',Description=N'" + dg + "',ContactName=N'" + tencon + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactEmail='" + emailcon + "',ContactOfficeTel='" + dtcq + "',ContactHomeTel='" + dtnr + "',ContactAddress=N'" + dccon + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',IssueBy=N'" + noicap + "',Inactive='" + ntd + "',DueTime='" + hn + "',MaximizeDebtAmount='" + sntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',Province='" + tinh + "',District='" + quan + "',AccountingObjectCategory=N'" + khncc + "',Village=N'" + cbprovince.Text + "' where AccountingObjectCode='" + txtma.Text + "'");
             *          gen.ExcuteNonquery("update hamaco_vithanh.dbo.AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',Address=N'" + dc + "',Tel='" + dt + "',Fax='" + fax + "',EmailAddress='" + email + "',Website=N'" + web + "',BankAccount='" + tknh + "',BankName=N'" + tnh + "',CompanyTaxCode='" + mst + "',Description=N'" + dg + "',ContactName=N'" + tencon + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactEmail='" + emailcon + "',ContactOfficeTel='" + dtcq + "',ContactHomeTel='" + dtnr + "',ContactAddress=N'" + dccon + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',IssueBy=N'" + noicap + "',Inactive='" + ntd + "',DueTime='" + hn + "',MaximizeDebtAmount='" + sntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',Province='" + tinh + "',District='" + quan + "',AccountingObjectCategory=N'" + khncc + "',Village=N'" + cbprovince.Text + "' where AccountingObjectCode='" + txtma.Text + "'");
             *          //gen.ExcuteNonquery("update hamaco_qlk.dbo.AccountingObject set AccountingObjectName=N'" + name + "',BranchID='" + branchID + "',Address=N'" + dc + "',Tel='" + dt + "',Fax='" + fax + "',EmailAddress='" + email + "',Website=N'" + web + "',BankAccount='" + tknh + "',BankName=N'" + tnh + "',CompanyTaxCode='" + mst + "',Description=N'" + dg + "',ContactName=N'" + tencon + "',ContactTitle=N'" + chucdanh + "',ContactMobile='" + dtdd + "',ContactEmail='" + emailcon + "',ContactOfficeTel='" + dtcq + "',ContactHomeTel='" + dtnr + "',ContactAddress=N'" + dccon + "',IsPersonal='" + person + "',IdentificationNumber='" + cmnd + "',IssueDate='" + ngaycap + "',IssueBy=N'" + noicap + "',Inactive='" + ntd + "',DueTime='" + hn + "',MaximizeDebtAmount='" + sntd + "',IsVendor='" + ncc + "',IsCustomer='" + kh + "',Province='" + tinh + "',District='" + quan + "',AccountingObjectCategory=N'" + khncc + "',Village=N'" + cbprovince.Text + "' where AccountingObjectCode='" + txtma.Text + "'");
             *          this.myac();
             *          this.Close();
             *      }
             *  }
             *  else
             *  {
             *      try
             *      {
             *          string kq = gen.GetString("select * from hamaco.dbo.AccountingObject where CompanyTaxCode='" + txtmst.Text + "' and CompanyTaxCode<>''");
             *          MessageBox.Show("Mã số thuế này đã tồn tại. Vui lòng kiểm tra lại.", "Thông báo");
             *          return;
             *      }
             *      catch
             *      {
             *          string nv = "False";
             *          string insu = "False";
             *          string labe = "False";
             *          string sql = "insert into hamaco.dbo.AccountingObject(AccountingObjectID,AccountingObjectCode,AccountingObjectName,BranchID,Address,Tel,Fax,EmailAddress,Website,BankAccount,BankName,CompanyTaxCode,Description,ContactName,ContactTitle,ContactMobile,ContactEmail,ContactOfficeTel,ContactHomeTel,ContactAddress,IsPersonal,IdentificationNumber,IssueDate,IssueBy,Inactive,DueTime,MaximizeDebtAmount,IsVendor,IsCustomer,Province,District,IsEmployee,Insured,LabourUnionFee,FamilyDeductionAmount,AccountingObjectCategory,Village)  values(newid(),'" + code + "',N'" + name + "','" + branchID + "',N'" + dc + "','" + dt + "','" + fax + "','" + email + "',N'" + web + "','" + tknh + "',N'" + tnh + "','" + mst + "',N'" + dg + "',N'" + tencon + "',N'" + chucdanh + "','" + dtdd + "','" + emailcon + "','" + dtcq + "','" + dtnr + "',N'" + dccon + "','" + person + "','" + cmnd + "','" + ngaycap + "',N'" + noicap + "','" + ntd + "','" + hn + "','" + sntd + "','" + ncc + "','" + kh + "','" + tinh + "','" + quan + "','" + nv + "','" + insu + "','" + labe + "','0',N'" + khncc + "',N'" + cbprovince.Text + "')";
             *          cuspro.checkcuspro(active, txtma, txttc, sql, this);
             *      }
             *  }
             *  if (active == "1")
             *      gen.ExcuteNonquery("insert into MSC_Auditting_Log(EventID,LoginName,ComputerName,Time,PermissionTypeAlias,Reference) values(newid(),'" + gen.GetString("select UserName from MSC_User where UserID='" + userid + "'").ToString() + "','" + System.Environment.MachineName + "',GETDATE(),N'Sửa mã khách','" + txtma.Text + "')");
             *  else
             *      gen.ExcuteNonquery("insert into MSC_Auditting_Log(EventID,LoginName,ComputerName,Time,PermissionTypeAlias,Reference) values(newid(),'" + gen.GetString("select UserName from MSC_User where UserID='" + userid + "'").ToString() + "','" + System.Environment.MachineName + "',GETDATE(),N'Thêm mã khách','" + txtma.Text + "')");
             * }*/
            AccountingObject data = new AccountingObject();

            if (active == "0")
            {
                data.AccountingObjectID = Guid.NewGuid();// tao guiid moi
            }
            else
            {
                data.AccountingObjectID = Guid.Parse(role);;
            }
            //data.ClientID = Globals.clientid;
            data.CompanyCode          = Globals.companycode;
            data.AccountingObjectCode = code;
            data.AccountingObjectName = name;
            //data.BranchID = Guid.Parse(branch);

            data.Address        = dc;
            data.EmailAddress   = email;
            data.BankAccount    = tknh;
            data.BankName       = tnh;
            data.CompanyTaxCode = mst;
            data.ContactTitle   = chucdanh;
            data.ContactMobile  = dtdd;

            data.ContactOfficeTel     = dtcq;
            data.ContactHomeTel       = dtnr;
            data.IsPersonal           = true;
            data.IsEmployee           = false;
            data.IdentificationNumber = cmnd;
            data.IssueDate            = ngaycap;
            data.ContactTitle         = chucdanh;
            data.IssueBy = noicap;

            data.Tel     = txtdt.Text;
            data.Fax     = txtfax.Text;
            data.Website = txtwweb.Text;

            data.Description = txtdg.Text;
            try {
                data.MaximizeDebtAmount = Int32.Parse(txtsntd.Text);
                data.DueTime            = Int32.Parse(txthn.Text);
            } catch
            {
            }

            data.ContactName = txttencon.Text;

            data.ContactAddress = txtdccon.Text;
            data.ContactEmail   = txtemailcon.Text;

            data.Inactive = chbntd.Checked;
            if (rbkhncc.Checked == true)
            {
                data.IsCustomer = true;
                data.IsVendor   = true;
            }
            else
            {
                if (rbncc.Checked == true)
                {
                    data.IsVendor = true;
                }
                else
                {
                    data.IsCustomer = true;
                }
            }
            try
            {
                //data.BranchID = Guid.Parse(cbbranch.Text);
                data.BranchID = Guid.Parse(branch);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message + active, "branch", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            data.Inactive   = chbntd.Checked;
            data.IsPersonal = rbcn.Checked;
            data.Province   = tinh;
            data.District   = quan;

            var db = gen.GetNewEntity(); // khai bao new entity Framework
            {
                try
                {
                    if (active == "0")
                    {
                        db.AccountingObjects.Add(data);                //insert
                    }
                    else
                    {
                        db.Entry(data).State = System.Data.Entity.EntityState.Modified;  // update
                    }
                    db.SaveChanges();
                    XtraMessageBox.Show("Submit successfully", "tsbtsave_Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                //catch (DbUpdateException ex) // exception khac
                catch (DbUpdateConcurrencyException ex) // exception khac
                {
                    XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message + active, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //  txtSQL.Text = ex.Message + data + active;
                }
            }
        }