private void butOk_Click(object sender, System.EventArgs e) { if (!kiemtra()) { return; } s_mmyy = mm.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); if (!ttb.bMmyy(s_mmyy)) { MessageBox.Show(lan.Change_language_MessageText("Số liệu ") + nhom.Text + lan.Change_language_MessageText(" tháng ") + mm.Value.ToString() + "/" + yyyy.Value.ToString() + lan.Change_language_MessageText(" chưa tạo !"), ttb.Msg); mm.Focus(); return; } i_nhom = int.Parse(nhom.SelectedValue.ToString()); Cursor = Cursors.WaitCursor; s_manguon = ttb.get_data("select nguon from " + user + ".ttb_dmphieu where id=" + i_loai).Tables[0].Rows[0][0].ToString(); s_makp = ""; s_makho = ""; s_ngay = ngay.Text.Substring(0, 10); s_tenkp = makp.Text; s_phieu = phieu.Text; s_tennhom = nhom.Text; i_somay = 1; i_buoi = 0; i_makp = int.Parse(makp.SelectedValue.ToString()); if (i_loai == 2) { i_macstt = int.Parse(matutruc.SelectedValue.ToString()); } else { i_macstt = 0; } i_phieu = int.Parse(phieu.SelectedValue.ToString()); r = ttb.getrowbyid(dtmakp, "id=" + i_makp); if (r != null) { s_makp = r["makp"].ToString(); //DataRow r1 = m.getrowbyid(dtkp, "loai=1 and makp='" + s_makp + "'");// //if (r1 != null) s_makp = "";//neu la phong kham--> makp=""--> khong hoan tra duoc // i_somay = int.Parse(r["somay"].ToString()); } for (int i = 0; i < makho.Items.Count; i++) { s_makho += dtkho.Rows[i]["id"].ToString() + ","; } dt = ttb.get_data("select a.id,a.makp,b.ten from " + user + s_mmyy + ".ttb_duyet a," + user + ".d_duockp b where a.makp=b.id and a.nhom=" + i_nhom + " and to_char(a.ngay,'dd/mm/yyyy')='" + ((s_ngay.Length > 10)?s_ngay.Substring(0, 10):s_ngay) + "'" + " and a.loai=" + i_loai + " and a.phieu=" + i_phieu + " and a.makhoa=" + i_makp).Tables[0]; if (dt.Rows.Count != 0) { l_duyet = decimal.Parse(dt.Rows[0][0].ToString()); if (i_loai == 2 && int.Parse(dt.Rows[0]["makp"].ToString()) != int.Parse(matutruc.SelectedValue.ToString())) { MessageBox.Show(lan.Change_language_MessageText("Khoa :") + " " + makp.Text + lan.Change_language_MessageText(" ngày : ") + " " + ngay.Text.Substring(0, 10) + " " + lan.Change_language_MessageText("phiếu : ") + " " + phieu.Text + "\n" + lan.Change_language_MessageText("đã chọn tủ trực :") + " " + dt.Rows[0]["ten"].ToString(), ttb.Msg); matutruc.SelectedValue = dt.Rows[0]["makp"].ToString(); matutruc.Focus(); return; } } else { l_duyet = 0; } if (i_benhnhan == 0 && s_makp == "") { s_makp = "xx"; } r = ttb.getrowbyid(dtphieu, "id=" + i_phieu); if (r != null) { i_buoi = int.Parse(r["buoi"].ToString()); } if (ttb.bKiemtra_duyet(i_nhom)) { ttb.upd_tonkho(s_mmyy, i_nhom, 0); } Cursor = Cursors.Default; string ngayt = ttb.DateToString("dd/MM/yyyy", ttb.StringToDate("01/" + mm.Value.ToString().PadLeft(2, '0') + "/" + yyyy.Value.ToString().PadLeft(4, '0')).AddMonths(-1)); string mmyyt = ttb.mmyy(ngayt); if (i_loai == 2) { if (ttb.bMmyy(mmyyt)) { sql = "select a.* from " + user + mmyyt + ".ttb_xtutrucll a," + user + mmyyt + ".ttb_duyet b "; sql += " where a.idduyet=b.id "; sql += " and nhom=" + i_nhom + " and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "'"; sql += " and loai=" + i_loai + " and phieu=" + i_phieu + " and makhoa=" + i_makp; if (ttb.get_data(sql).Tables[0].Rows.Count > 0) { MessageBox.Show(lan.Change_language_MessageText("Đã nhập trong tháng") + " " + mmyyt.Substring(0, 2) + lan.Change_language_MessageText(" năm 20") + mmyyt.Substring(2, 2), ttb.Msg); mm.Value = decimal.Parse(mmyyt.Substring(0, 2)); yyyy.Value = decimal.Parse("20" + mmyyt.Substring(2, 2)); mm.Focus(); return; } } } else if (i_loai == 1) { if (ttb.bMmyy(mmyyt)) { sql = "select a.* from " + user + mmyyt + ".ttb_dutrull a," + user + mmyyt + ".ttb_duyet b "; sql += " where a.idduyet=b.id "; sql += " and nhom=" + i_nhom + " and to_char(ngay,'dd/mm/yyyy')='" + s_ngay + "'"; sql += " and loai=" + i_loai + " and phieu=" + i_phieu + " and makhoa=" + i_makp; if (ttb.get_data(sql).Tables[0].Rows.Count > 0) { MessageBox.Show(lan.Change_language_MessageText("Đã nhập trong tháng") + " " + mmyyt.Substring(0, 2) + " " + lan.Change_language_MessageText("năm 20") + mmyyt.Substring(2, 2), ttb.Msg); mm.Value = decimal.Parse(mmyyt.Substring(0, 2)); yyyy.Value = decimal.Parse("20" + mmyyt.Substring(2, 2)); mm.Focus(); return; } } } ttb.close(); this.Close(); }
private void load_treeview() { string tu = ttb.DateToString("dd/MM/yyyy", ttb.StringToDate(s_ngay).AddDays(-1.0 * Convert.ToDouble(songay.Value))); string den = ttb.DateToString("dd/MM/yyyy", ttb.StringToDate(s_ngay));//.AddDays(Convert.ToDouble(songay.Value)) sql = "select c.makp,b.mabd,sum(b.slyeucau-b.slthuc) as soluong, c.loai,c.phieu, f.ten as tenphieu,to_char(c.ngay,'dd/mm/yyyy') as ngay "; sql += " from " + xxx + ".ttb_haophill a," + xxx + ".ttb_haophict b," + xxx + ".ttb_duyet c," + user + ".ttb_dmbd d," + user + ".ttb_dmphieu e, " + user + ".ttb_loaiphieu f "; sql += " where a.id=b.id and a.idduyet=c.id and b.mabd=d.id and c.loai=e.id and c.phieu=f.id "; sql += " and c.nhom=" + i_nhom + " and c.loai=" + i_loai; sql += " and to_date(to_char(c.ngay,'dd/mm/yyyy'),'dd/mm/yyyy') between to_date('" + tu + "','dd/mm/yyyy') and to_date('" + den + "','dd/mm/yyyy')"; if (s_kho != "") { sql += " and b.makho in (" + s_kho.Substring(0, s_kho.Length - 1) + ")"; } sql += " and c.done<>0 and b.slyeucau>b.slthuc and b.tutruc=0 group by c.makp,b.mabd,c.loai,c.phieu, f.ten,c.ngay order by c.makp,c.loai,c.phieu,b.mabd"; treeView1.Nodes.Clear(); TreeNode node = new TreeNode(); TreeNode node2 = new TreeNode(); DataTable dtngay = ttb.get_data(sql).Tables[0]; DataRow [] dr; i_makp = 0; string s_makp = ""; string str4 = ""; foreach (DataRow r1 in dtngay.Select("true", "makp,ngay,loai,phieu,mabd")) { //if (s_makp!=r1["makp"].ToString()+r1["loai"].ToString()+r1["phieu"].ToString()) //{ // i_makp=int.Parse(r1["makp"].ToString()); // s_makp=r1["makp"].ToString()+r1["loai"].ToString()+r1["phieu"].ToString(); // r=ttb.getrowbyid(dtkp,"id="+i_makp); // if (r!=null) // { // node=treeView1.Nodes.Add(r["ten"].ToString()+" - "+r1["tenphieu"].ToString()); // dr=dtngay.Select("makp="+i_makp+" and loai="+r1["loai"].ToString()+" and phieu="+r1["phieu"].ToString()); // for(int i=0;i<dr.Length;i++) // { // r=ttb.getrowbyid(dtdmbd,"id="+int.Parse(dr[i]["mabd"].ToString())); // if (r!=null) node.Nodes.Add(r["ten"].ToString().Trim()+"/"+r["tenhc"].ToString().Trim()+" "+r["dang"].ToString().Trim()+" ("+dr[i]["soluong"].ToString().Trim()+")"); // } // } //} if (i_makp != int.Parse(r1["makp"].ToString())) { i_makp = int.Parse(r1["makp"].ToString()); r = d.getrowbyid(dtkp, "id=" + i_makp); if (r != null) { node = treeView1.Nodes.Add(r["ten"].ToString()); } str4 = ""; } if (str4 != (r1["ngay"].ToString() + r1["loai"].ToString() + r1["phieu"].ToString())) { str4 = r1["ngay"].ToString() + r1["loai"].ToString() + r1["phieu"].ToString(); node2 = node.Nodes.Add(r1["ngay"].ToString().Substring(0, 5) + " - " + r1["tenphieu"].ToString()); DataRow[] rowArray = dtngay.Select(string.Concat(new object[] { "makp=", i_makp, " and ngay='", r1["ngay"].ToString(), "' and loai=", r1["loai"].ToString(), " and phieu=", r1["phieu"].ToString() })); for (int i = 0; i < rowArray.Length; i++) { r = d.getrowbyid(dtdmbd, "id=" + int.Parse(rowArray[i]["mabd"].ToString())); if (r != null) { node2.Nodes.Add(r["ten"].ToString().Trim() + "/" + r["tenhc"].ToString().Trim() + " " + r["dang"].ToString().Trim() + " (" + rowArray[i]["soluong"].ToString().Trim() + ")"); } } } } }