public void tsbtbranch(string a, Form1 F, DevExpress.XtraGrid.Views.Grid.GridView view, string userid) { try { Frm_branch m = new Frm_branch(); m.myac = new Frm_branch.ac(F.refreshbranch); m.getactive(a); m.getuserid(userid); if (a == "1") { m.getrole(view.GetRowCellValue(view.FocusedRowHandle, "ID").ToString()); } m.ShowDialog(); } catch { MessageBox.Show("Vui lòng chọn đơn vị trước khi sửa."); } }
public void checkbranch(string ac, TextBox a, TextBox b, Frm_branch F, DevExpress.XtraEditors.LookUpEdit ledv, TextBox txtdg, RadioButton radioButton1, string role, DevExpress.XtraEditors.LookUpEdit lekho, DevExpress.XtraEditors.LookUpEdit leprovince, TextBox txtmst) { if (a.Text == "") { MessageBox.Show("Mã đơn vị không được bỏ trống.", "HAMACO"); } else if (b.Text == "") { MessageBox.Show("Tên đơn vị không được bỏ trống.", "HAMACO"); } else { string sql, dv; string th = radioButton1.Checked.ToString(); string kho = gen.GetString("select * from Stock where StockCode='" + lekho.EditValue + "'"); if (ac == "1") { try { dv = ledv.EditValue.ToString(); DataTable temp = new DataTable(); temp = gen.GetTable("select * from Branch where BranchCode='" + dv + "'"); dv = temp.Rows[0][0].ToString(); int bac = Int32.Parse(temp.Rows[0][9].ToString()) + 1; sql = "update Branch set BranchCode=N'" + a.Text + "', BranchName=N'" + b.Text + "',Description=N'" + txtdg.Text + "',IsDependent='" + th + "',Parent='" + dv + "',Grade=" + bac + ",StockBranch='" + kho + "',Province='" + leprovince.EditValue.ToString() + "',Code='" + txtmst.Text + "' where BranchID='" + role + "'"; gen.ExcuteNonquery("update Branch set IsParent='True' where BranchID='" + dv + "'"); } catch { sql = "update Branch set BranchCode=N'" + a.Text + "', BranchName=N'" + b.Text + "',Description=N'" + txtdg.Text + "',IsDependent='" + th + "',Parent=NULL,Grade=1,StockBranch='" + kho + "',Province='" + leprovince.EditValue.ToString() + "',Code='" + txtmst.Text + "' where BranchID='" + role + "'"; } gen.ExcuteNonquery(sql); F.myac(); F.Close(); } else { try { string kq = gen.GetString("select * from Branch where BranchCode='" + a.Text + "'"); MessageBox.Show("Mã đơn vị này đã tồn tại.", "HAMACO"); } catch { try { dv = ledv.EditValue.ToString(); DataTable temp = new DataTable(); temp = gen.GetTable("select * from Branch where BranchCode='" + dv + "'"); dv = temp.Rows[0][0].ToString(); int bac = Int32.Parse(temp.Rows[0][9].ToString()) + 1; sql = "insert into Branch values(newid(),'" + a.Text + "',N'" + b.Text + "',N'" + txtdg.Text + "','" + th + "','False','False','False','" + dv + "'," + bac + ",'" + kho + "','" + leprovince.EditValue.ToString() + "','" + txtmst.Text + "')"; gen.ExcuteNonquery("update Branch set IsParent='True' where BranchID='" + dv + "'"); } catch { sql = "insert into Branch values(newid(),'" + a.Text + "',N'" + b.Text + "',N'" + txtdg.Text + "','" + th + "','False','False','False',NULL,1,'" + kho + "','" + leprovince.EditValue.ToString() + "','" + txtmst.Text + "')"; } gen.ExcuteNonquery(sql); F.myac(); F.Close(); } } } }