private void butIn_Click(object sender, System.EventArgs e) { Tao_dataset(); tongcong = 0; DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { get_data(mmyy); } } } if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); return; } ngay = (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text; exp_excel(); }
private bool kiemtra() { s_kho = ""; if (kho.CheckedItems.Count == 0) { for (int i = 0; i < kho.Items.Count; i++) { kho.SetItemCheckState(i, CheckState.Checked); } } for (int i = 0; i < kho.Items.Count; i++) { if (kho.GetItemChecked(i)) { s_kho += dtdmkho.Rows[i]["id"].ToString() + ","; } } sql = "select * from " + user + ".ttb_dmkho where nhom=" + i_nhom; if (s_kho != "") { sql += " and id in (" + s_kho.Substring(0, s_kho.Length - 1) + ")"; } if (s_makho != "") { sql += " and id in (" + s_makho.Substring(0, s_makho.Length - 1) + ")"; } sql += " order by stt"; dtkho = ttb.get_data(sql).Tables[0]; Tao_dataset(tu.Value, den.Value); // DateTime dt1 = ttb.StringToDate(tu.Text); //.AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text); //.AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { get_xuat(mmyy); get_hoantra(mmyy); } } } // if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); return(false); } return(true); }
private void Tao_dataset() { ds = new DataSet(); ds.ReadXml("..\\..\\..\\xml\\ttb_bcngay.xml"); dsngay.Clear(); DateTime dt1 = ttb.StringToDate(tu.Text); DateTime dt2 = ttb.StringToDate(den.Text); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); sql = "select distinct to_char(ngay,'yymmdd') ngay,to_char(ngay,'dd/mm') ten from ttb_xuatsdll where nhom=" + i_nhom + " and to_date(ngay,'dd/mm/yy') between to_date('" + tu.Text + "','dd/mm/yy') and to_date('" + den.Text + "','dd/mm/yy')"; sql += "union all select distinct to_char(ngay,'yymmdd') ngay,to_char(ngay,'dd/mm') ten from ttb_xuatll where nhom=" + i_nhom + " and loai='XK' and to_date(ngay,'dd/mm/yy') between to_date('" + tu.Text + "','dd/mm/yy') and to_date('" + den.Text + "','dd/mm/yy')"; sql += "union all select distinct to_char(ngay,'yymmdd') ngay,to_char(ngay,'dd/mm') ten from ttb_ngtrull where nhom=" + i_nhom + " and to_date(ngay,'dd/mm/yy') between to_date('" + tu.Text + "','dd/mm/yy') and to_date('" + den.Text + "','dd/mm/yy')"; sql += "union all select distinct to_char(a.ngay,'yymmdd') ngay,to_char(a.ngay,'dd/mm') ten from bhytkb a,bhytthuoc b where a.id=b.id and a.nhom=" + i_nhom + " and to_date(a.ngay,'dd/mm/yy') between to_date('" + tu.Text + "','dd/mm/yy') and to_date('" + den.Text + "','dd/mm/yy')"; dr = ttb.get_data(sql).Tables[0].Select("ngay<>''", "ngay");//mmyy for (int k = 0; k < dr.Length; k++) { r1 = ttb.getrowbyid(dsngay.Tables[0], "ngay='" + dr[k]["ngay"].ToString() + "'"); if (r1 == null) { r2 = dsngay.Tables[0].NewRow(); r2["ngay"] = dr[k]["ngay"].ToString(); r2["ten"] = dr[k]["ten"].ToString(); dsngay.Tables[0].Rows.Add(r2); dc = new DataColumn(); dc.ColumnName = "SL_" + dr[k]["ngay"].ToString().Trim(); dc.DataType = Type.GetType("System.Decimal"); ds.Tables[0].Columns.Add(dc); } } } } dc = new DataColumn(); dc.ColumnName = "TONGCONG"; dc.DataType = Type.GetType("System.Decimal"); ds.Tables[0].Columns.Add(dc); }
private bool kiemtra() { s_kho = ""; if (kho.CheckedItems.Count == 0) { for (int i = 0; i < kho.Items.Count; i++) { kho.SetItemCheckState(i, CheckState.Checked); } } for (int i = 0; i < kho.Items.Count; i++) { if (kho.GetItemChecked(i)) { s_kho += dtdmkho.Rows[i]["id"].ToString() + ","; } } DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; ds.Clear(); for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { get_xuat(mmyy); } } } if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); return(false); } return(true); }
private void butIn_Click(object sender, System.EventArgs e) { s_madv = ""; for (int i = 0; i < madv.Items.Count; i++) { if (madv.GetItemChecked(i)) { s_madv += dsdmnx.Tables[0].Rows[i]["id"].ToString() + ","; } } ds.Clear(); DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { get_nhap(mmyy); } } } if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); return; } frmReport f = new frmReport(ttb, ds.Tables[0], "d_Bkhoadon.rpt", (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, "", "", "", "", "", "", "", "", ""); f.ShowDialog(); }
private void load_grid() { ds.Clear(); DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { xxx = user + mmyy; sql = "select a.id,a.sophieu,to_char(a.ngaysp,'dd/mm/yyyy') as ngaysp,a.sohd,to_char(a.ngayhd,'dd/mm/yyyy') as ngayhd,"; sql += "c.ten as madv,nullif(b.no,a.no) as no,nullif(b.co,a.co) as co,b.sotien,b.datra"; sql += " from ttb_nhapll a,ttb_thanhtoan b," + user + ".ttb_dmnx c"; sql += " where a.mmyy='" + mmyy + "' and a.id=b.id and a.madv=c.id and a.loai='M' and b.sotien<>0 and a.nhom=" + i_nhom; sql += " and " + ttb.for_ngay("a.ngaysp", stime) + " between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")"; foreach (DataRow r in ttb.get_data(sql).Tables[0].Rows) { ttb.updrec_congno(ds.Tables[0], mmyy, decimal.Parse(r["id"].ToString()), r["sophieu"].ToString(), r["ngaysp"].ToString(), r["sohd"].ToString(), r["ngayhd"].ToString(), r["madv"].ToString(), r["no"].ToString(), r["co"].ToString(), decimal.Parse(r["sotien"].ToString()), decimal.Parse(r["datra"].ToString())); } } } } dataGrid1.DataSource = ds.Tables[0]; CurrencyManager cm = (CurrencyManager)BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; DataView dv = (DataView)cm.List; dv.AllowNew = false; tinh_giatri("true"); }
private void get_nhap() { DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { upd_data(mmyy); } } } ds.AcceptChanges(); }
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() + ")"); } } } } }
private void cmdOk_Click(object sender, System.EventArgs e) { ttb.setStandar(); string Ngaydemo = ttb.Ngaydemo("khottb"); if (Ngaydemo != "") { int songay = ttb.Songaydemo; if (songay != 0) { decimal conlai = songay - ttb.songay(ttb.StringToDate(ttb.ngayhienhanh_server.Substring(0, 10)), ttb.StringToDate(Ngaydemo), 0); if (conlai <= 0) { MessageBox.Show("Đã hết thời gian chạy thử\nLiên hệ nhà cung cấp:\nPhone : 08.7155019\nMobile : 090 3937066", ttb.Msg); return; } else if (conlai <= 3) { MessageBox.Show("Thời gian chạy thử còn " + conlai.ToString() + " ngày", ttb.Msg); } } } DataTable dtver = m.get_data("select * from version").Tables[0]; if (dtver.Rows.Count > 0) { if (dtver.Rows[0]["khottb"].ToString().Trim() != "") { string tenfile = ttb.file_exe("TrangThietBi"); if (dtver.Rows[0]["khottb"].ToString().Trim() != ttb.file_modify(tenfile)) { MessageBox.Show("Không đúng version đang sử dụng !", ttb.Msg); Application.Exit(); } } } if (!kiemtra()) { MessageBox.Show("Tên người dùng và mật khẩu không tìm thấy !", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); txtuser.Focus(); return; } mMmyy = mm.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2); mNgay = ngay.Text; bool bKiemtra = false; string s_PassWord = txtpassword.Text; string s_PasswordLinks = "Links03031952@toancau" + DateTime.Now.ToString("ddMMyyyy"); iNhomkho = (int)LibDuoc.ID.NhomKho.TTB; if (txtuser.Text != LibTTB.AccessData.links_userid && s_PassWord != s_PasswordLinks) { if (!bTao && !ttb.bMmyy(mMmyy)) { MessageBox.Show("Bạn không có quyền tạo số liệu tháng mới !", ttb.Msg); return; } int iret = ttb.bKiemtrasolieu(iNhomkho, mMmyy, iUserid); if (iret == 0) { if (MessageBox.Show("Bạn có muốn tạo số liệu tháng " + mMmyy.Substring(0, 2) + " năm " + mMmyy.Substring(2, 2) + "?", ttb.Msg, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Cursor = Cursors.WaitCursor; string mmyyt = ttb.Mmyy_truoc(mMmyy); ttb.tao_partition(mMmyy); if (!ttb.bKhoaso(iNhomkho, mmyyt) && ttb.bAuto_tonkho(iNhomkho)) { bKiemtra = true; ttb.upd_tonkho(iNhomkho, mmyyt); } foreach (DataRow r in ttb.get_data("select * from " + user + ".ttb_dmkho where nhom=" + iNhomkho).Tables[0].Rows) { foreach (DataRow r1 in m.get_data("select * from " + m.user + ".d_duockp where nhom like '%" + iNhomkho.ToString() + ",%'").Tables[0].Rows) { ttb.upd_kiemtratutrucdau(mMmyy, int.Parse(r1["id"].ToString()), int.Parse(r["id"].ToString()), iUserid); } ttb.upd_kiemtratondau(mMmyy, int.Parse(r["id"].ToString()), iUserid); } ttb.upd_tonkho(mMmyy, iNhomkho, 0); ttb.upd_khoaso(iNhomkho, ttb.Mmyy_truoc(mMmyy), iUserid); ttb.upd_cosotutruc(iNhomkho, ttb.Mmyy_truoc(mMmyy), mMmyy); xxx = user; ttb.execute_data("delete from " + xxx + ".ttb_tonkhoct where tondau=0 and slnhap=0 and slxuat=0"); ttb.execute_data("delete from " + xxx + ".ttb_tonkhoth where tondau=0 and slnhap=0 and slxuat=0"); ttb.execute_data("delete from " + xxx + ".ttb_tutrucct where tondau=0 and slnhap=0 and slxuat=0"); ttb.execute_data("delete from " + xxx + ".ttb_tutructh where tondau=0 and slnhap=0 and slxuat=0"); Cursor = Cursors.Default; } else { return; } } else if (iret == -1) { return; } if (iNhomkho != 0 && !bKiemtra) { if (!ttb.bKhoaso(iNhomkho, mMmyy) && ttb.get_kiemtra(mMmyy, iNhomkho, ngay.Text)) { Cursor = Cursors.WaitCursor; ttb.upd_kiemtra(mMmyy, iNhomkho, ngay.Text, iUserid); ttb.upd_tonkho(iNhomkho, mMmyy); Cursor = Cursors.Default; } } } else { mUserid = LibTTB.AccessData.links_userid + LibTTB.AccessData.links_pass; } this.mExit = false; this.Close(); }
private void Taotable() { ds = new DataSet(); ds.ReadXml("..\\..\\..\\xml\\m_biendong.xml"); DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; i_rec = 0; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { xxx = user + mmyy; sql = "select distinct to_char(a.ngay,'yymmdd') as ngay "; sql += " from " + xxx + ".ttb_theodoigia a," + user + ".ttb_dmbd b," + user + ".ttb_dmhang c," + user + ".ttb_nhomhang d where a.mabd=b.id and b.mahang=c.id and c.loai=d.id"; sql += " and b.nhom=" + i_nhom; if (s_nhom != "") { sql += " and b.manhom in (" + s_nhom.Substring(0, s_nhom.Length - 1) + ")"; } if (s_loai != "") { sql += " and b.maloai in (" + s_loai.Substring(0, s_loai.Length - 1) + ")"; } if (s_hang != "") { sql += " and b.mahang in (" + s_hang.Substring(0, s_hang.Length - 1) + ")"; } sql += " and a.ngay between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")"; foreach (DataRow r in ttb.get_data(sql).Tables[0].Select("ngay<>''", "ngay")) { try { dc = new DataColumn(); dc.ColumnName = r["ngay"].ToString(); dc.DataType = Type.GetType("System.Decimal"); ds.Tables[0].Columns.Add(dc); i_rec++; } catch {} } } } } dc = new DataColumn(); dc.ColumnName = "tyle"; dc.DataType = Type.GetType("System.Decimal"); ds.Tables[0].Columns.Add(dc); dc = new DataColumn(); dc.ColumnName = "ghichu"; dc.DataType = Type.GetType("System.String"); ds.Tables[0].Columns.Add(dc); }
private void taotable() { if (!kiemtra()) { return; } i_dongia = ttb.d_dongia_le(int.Parse(nhom.SelectedValue.ToString())); ds.Clear(); s_loai = ""; s_phieu = ""; for (int i = 0; i < loai.Items.Count; i++) { if (loai.GetItemChecked(i)) { s_loai += dtloai.Rows[i]["id"].ToString().Trim() + ","; } } for (int i = 0; i < phieu.Items.Count; i++) { if (phieu.GetItemChecked(i)) { s_phieu += dtphieu.Rows[i]["id"].ToString().Trim() + ","; } } dtdmbd = ttb.get_data("select * from " + user + ".ttb_dmbd where nhom=" + int.Parse(nhom.SelectedValue.ToString())).Tables[0]; string cont = " and a.makp=" + int.Parse(makp.SelectedValue.ToString()) + " and a.nhom=" + int.Parse(nhom.SelectedValue.ToString()); cont += " and a.ngay between to_date('" + tu.Text + "'," + stime + ") and to_date('" + den.Text + "'," + stime + ")"; if (s_loai != "") { cont += " and a.loai in (" + s_loai.Substring(0, s_loai.Length - 1) + ")"; } if (s_phieu != "") { cont += " and a.phieu in (" + s_phieu.Substring(0, s_phieu.Length - 1) + ")"; } if (imp.Visible) { if (imp.Checked) { cont += " and c.manhom in (31,55)"; } else { cont += " and c.manhom not in (31,55)"; } } s_makho = ""; s_tenkho = ""; for (int i = 0; i < makho.Items.Count; i++) { if (makho.GetItemChecked(i)) { s_makho += dtkho.Rows[i]["id"].ToString().Trim() + ","; s_tenkho += dtkho.Rows[i]["ten"].ToString().Trim() + ";"; } } if (s_makho == "") { for (int i = 0; i < makho.Items.Count; i++) { s_makho += dtkho.Rows[i]["id"].ToString().Trim() + ","; s_tenkho += dtkho.Rows[i]["ten"].ToString().Trim() + ";"; } } if (s_makho != "") { cont += " and b.makho in (" + s_makho.Substring(0, s_makho.Length - 1) + ")"; } DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { get_xuat(mmyy, cont); get_hoantra(mmyy, cont); } } } sort(); }
private void butIn_Click(object sender, System.EventArgs e) { ds.Clear(); s_kho = ""; s_tennhom = ""; if (kho.CheckedItems.Count == 0) { for (int i = 0; i < kho.Items.Count; i++) { kho.SetItemCheckState(i, CheckState.Checked); } } for (int i = 0; i < kho.Items.Count; i++) { if (kho.GetItemChecked(i)) { s_kho += dtdmkho.Rows[i]["id"].ToString() + ","; s_tennhom += dtdmkho.Rows[i]["ten"].ToString() + ","; } } s_manhom = ""; for (int i = 0; i < nhom.Items.Count; i++) { if (nhom.GetItemChecked(i)) { s_manhom += dtnhom.Rows[i]["id"].ToString() + ","; } } DateTime dt1 = ttb.StringToDate(tu.Text).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; string mmyy = ""; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { if (i_nhapxuat == 1) { get_nhap(mmyy); } else { get_xuat(mmyy); get_hoantra(mmyy); } } } } // if (ds.Tables[0].Rows.Count == 0) { MessageBox.Show("Không có số liệu !", ttb.Msg); return; } get_sort(); if (tenfile == "d_phieuxuat.rpt") { decimal d_tongcong = 0; foreach (DataRow r in dsxml.Tables[0].Rows) { d_tongcong += decimal.Parse(r["sotien"].ToString()); } frmReport f = new frmReport(ttb, dsxml.Tables[0], tenfile, "", tu.Text, "", "", "", "Xuất sử dụng", s_tennhom, doiso.Doiso_Unicode(Convert.ToInt64(d_tongcong).ToString()), "", ""); f.ShowDialog(); } else { frmReport f1 = new frmReport(ttb, dsxml.Tables[0], tenfile, (tu.Text == den.Text)?" Ngày :" + tu.Text:"Từ ngày :" + tu.Text + " đến :" + den.Text, (s_tennhom == "")?"":"Kho :" + s_tennhom, (manguon.SelectedIndex == -1)?"":"Nguồn :" + manguon.Text, "", this.Text.Trim().ToUpper(), "", "", "", "", ""); f1.ShowDialog(); } }
private void butOk_Click(object sender, System.EventArgs e) { if (ttb.songay(ttb.StringToDate(den.Text), ttb.StringToDate(tu.Text), 1) > i_songay) { MessageBox.Show("Số ngày in phiếu (" + i_songay.ToString() + ")", ttb.Msg); tu.Focus(); return; } if (makp.SelectedIndex == -1 || phieu.SelectedIndex == -1) { if (makp.SelectedIndex == -1) { makp.Focus(); } else { phieu.Focus(); } return; } i_makp = int.Parse(makp.SelectedValue.ToString()); i_phieu = int.Parse(phieu.SelectedValue.ToString()); s_makho = ""; s_tenkho = ""; s_madt = ""; s_tendt = ""; s_manguon = ""; s_tennguon = ""; if (madoituong.CheckedItems.Count == 0) { for (int i = 0; i < madoituong.Items.Count; i++) { s_madt += dtdt.Rows[i]["madoituong"].ToString() + ","; } } else { for (int i = 0; i < madoituong.Items.Count; i++) { if (madoituong.GetItemChecked(i)) { s_madt += dtdt.Rows[i]["madoituong"].ToString() + ","; s_tendt += dtdt.Rows[i]["doituong"].ToString() + ";"; } } } if (manguon.CheckedItems.Count == 0) { for (int i = 0; i < manguon.Items.Count; i++) { s_manguon += dtnguon.Rows[i]["id"].ToString().Trim() + ","; } } else { for (int i = 0; i < manguon.Items.Count; i++) { if (manguon.GetItemChecked(i)) { s_manguon += dtnguon.Rows[i]["id"].ToString().Trim() + ","; s_tennguon += dtnguon.Rows[i]["ten"].ToString() + ";"; } } } if (kho.CheckedItems.Count == 0) { for (int i = 0; i < kho.Items.Count; i++) { s_makho += dtkho.Rows[i]["id"].ToString().Trim() + ","; } } else { for (int i = 0; i < kho.Items.Count; i++) { if (kho.GetItemChecked(i)) { s_makho += dtkho.Rows[i]["id"].ToString().Trim() + ","; s_tenkho += dtkho.Rows[i]["ten"].ToString() + ";"; } } } ds.Clear(); s_idduyet = ""; string s_idstt = ""; foreach (DataRow r in ttb.get_data("select idduyet,sttduyet from " + xxx + ".ttb_ngayduyet where nhom=" + i_nhom + " and loai=" + i_loai + " and makp=" + i_makp + " and ngay between to_date('" + tu.Text + "','" + f_ngay + "') and to_date('" + den.Text + "','" + f_ngay + "') and phieu=" + i_phieu).Tables[0].Rows) { s_idduyet += "(a.id=" + decimal.Parse(r["idduyet"].ToString()); if (r["sttduyet"].ToString() != "") { s_idduyet += " and b.sttduyet in (" + r["sttduyet"].ToString().Trim().Substring(0, r["sttduyet"].ToString().Trim().Length - 1) + ")"; } s_idduyet += ") or "; s_idstt += "(a.id=" + decimal.Parse(r["idduyet"].ToString()); if (r["sttduyet"].ToString() != "") { s_idstt += " and b.stt in (" + r["sttduyet"].ToString().Trim().Substring(0, r["sttduyet"].ToString().Trim().Length - 1) + ")"; } s_idstt += ") or "; } if (s_idduyet == "") { MessageBox.Show("Không có số liệu !", ttb.Msg); tu.Focus(); return; } if (s_idstt != "") { s_idstt = s_idstt.Substring(0, s_idstt.Length - 4); } if (s_idduyet != "") { s_idduyet = s_idduyet.Substring(0, s_idduyet.Length - 4); } if (ttb.bSLYeucau(i_nhom)) { ds = ttb.get_slyeucau(s_mmyy, ds, dt, dtkho, i_loai, file1, file2, s_idstt, s_madt, s_makho, s_manguon, bBuhaophi, dtdt, bDoituong_phieulinh, bNhomin_mabd, s_doc, tu.Text, tu.Text); } if (xuatcstt.Checked) { tieude = "PHIẾU XUẤT TỦ TRỰC"; if (ttb.bPhieulinh_dongia(i_nhom)) { ds = ttb.get_xuatcstt_dongia(s_mmyy, ds, dt, dtkho, s_idduyet, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, i_nhom); } else { ds = ttb.get_xuatcstt(s_mmyy, ds, dt, dtkho, s_idduyet, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh); } } else { if (ttb.bPhieulinh_dongia(i_nhom)) { ds = ttb.get_slxuat_dongia(ds, dt, dtkho, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, ""); } else { ds = ttb.get_slxuat(ds, dt, dtkho, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, dtdt, bDoituong_phieulinh, ""); } if (bBuhaophi) { tieude = "PHIẾU BÙ"; } else { tieude = s_title; } } if (ds.Tables[0].Rows.Count == 0 && s_doc == "") { MessageBox.Show("Không có số liệu !", ttb.Msg); tu.Focus(); return; } if (ttb.bPhieulinh_dongia(i_nhom)) { ttb.sort_inphieu_dongia(dsxml, ds, ttb.bSLYeucau(i_nhom), s_mmyy, tu.Text, i_nhom, i_makp, i_loai, i_phieu, s_makho, s_madt, s_manguon, nguoilinh.Text, dtdt, bDoituong_phieulinh, (xuatcstt.Checked)?false:(i_loai == 2)?true:bBuhaophi); } else { ttb.sort_inphieu(dsxml, ds, ttb.bSLYeucau(i_nhom), s_mmyy, tu.Text, i_nhom, i_makp, i_loai, i_phieu, s_makho, s_madt, s_manguon, nguoilinh.Text, dtdt, bDoituong_phieulinh, (xuatcstt.Checked)?false:(i_loai == 2)?true:bBuhaophi); } if (bDoituong_phieulinh) { tenfile = (ttb.bPhieulinh_dongia(i_nhom))?"ttb_phieulanh_yc_dt_dg":"ttb_phieulanh_yc_dt"; tenfile = (ttb.Mabv_so == 701424)?"ttb_phieulanh_dt_dg":tenfile; } else if (bInngang) { tenfile = "ttb_phieulanh_ng"; } else { tenfile = (ttb.bSLYeucau(i_nhom))?"ttb_phieulanh_yc":"ttb_phieulanh"; tenfile += (ttb.bPhieulinh_dongia(i_nhom))?"_dg":""; } if (xem.Checked) { frmReport f = new frmReport(ttb, dsxml.Tables[0], tenfile + ".rpt", makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", ""); f.ShowDialog(this); } else { prn.Printer(ttb, dsxml, tenfile + ".rpt", makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "", (bInngang || bDoituong_phieulinh)?2:1, Convert.ToInt16(banin.Value)); MessageBox.Show("Đang in " + tieude, "In phiếu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (s_doc != "") { dsxml = ttb.get_slxuat_doc(dsxml, tu.Text, den.Text, s_mmyy, i_nhom, i_loai, i_phieu, i_makp, s_madt, s_makho, s_manguon, bBuhaophi, s_doc, bNhomin_mabd, nguoilinh.Text, "", null); if (dsxml.Tables[0].Rows.Count <= 0) { return; } tenfile = "ttb_pldoc.rpt"; if (xem.Checked) { frmReport f = new frmReport(ttb, dsxml.Tables[0], tenfile, makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", ""); f.ShowDialog(this); } else { prn.Printer(ttb, dsxml, tenfile, makp.Text, tieude, (tu.Text == den.Text)?"Ngày " + tu.Text:"Từ ngày " + tu.Text + " đến " + den.Text, phieu.Text, s_tendt, s_tenkho, s_tennguon, s_mmyy, "", "", 1, Convert.ToInt16(banin.Value)); MessageBox.Show("Đang in " + tieude, "In phiếu", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
private void get_data() { dsdn.Clear(); d_cothue = 0; i_soct = 0; string so = "'"; if (sohd.SelectedItems.Count > 0) { if (sohd.CheckedItems.Count == 0) { for (int i = 0; i < sohd.Items.Count; i++) { sohd.SetItemCheckState(i, CheckState.Checked); } } for (int i = 0; i < sohd.Items.Count; i++) { if (sohd.GetItemChecked(i)) { so += dtsohd.Rows[i]["sohd"].ToString().Trim() + "','"; i_soct++; } } } string sql = "select a.sohd,to_char(a.ngayhd,'dd/mm/yyyy') as ngayhd,a.sophieu,to_char(a.ngaysp,'dd/mm/yyyy') as ngaysp,"; sql += "sum(round(b.sotien+b.sotien*b.vat/100+b.cuocvc+b.chaythu," + i_thanhtien_le + ")) as sotien from xxx.ttb_nhapll a,xxx.ttb_nhapct b," + user + ".ttb_dmnx c where a.id=b.id and a.madv=c.id"; sql += " and a.ngayhd between to_date('" + tu.Text + "','" + f_ngay + "') and to_date('" + den.Text + "','" + f_ngay + "')"; sql += " and a.nhom=" + i_nhom + " and trim(c.ma)='" + madv.Text + "'"; if (so.Length > 1) { sql += " and trim(a.sohd) in (" + so.Substring(0, so.Length - 2) + ")"; } sql += " group by a.sohd,to_char(a.ngayhd,'dd/mm/yyyy'),a.sophieu,to_char(a.ngaysp,'dd/mm/yyyy')"; DateTime dt1 = ttb.StringToDate(tu.Text.Substring(0, 10)).AddDays(-ttb.iNgaykiemke); DateTime dt2 = ttb.StringToDate(den.Text.Substring(0, 10)).AddDays(ttb.iNgaykiemke); int y1 = dt1.Year, m1 = dt1.Month; int y2 = dt2.Year, m2 = dt2.Month; int itu, iden; DataRow r1, r2; DataRow [] dr; string mmyy = "", sql1; for (int i = y1; i <= y2; i++) { itu = (i == y1)?m1:1; iden = (i == y2)?m2:12; for (int j = itu; j <= iden; j++) { mmyy = j.ToString().PadLeft(2, '0') + i.ToString().Substring(2, 2); if (ttb.bMmyy(mmyy)) { sql1 = sql.Replace("xxx", user); foreach (DataRow r in ttb.get_data(sql1).Tables[0].Rows) { r1 = ttb.getrowbyid(dsdn.Tables[0], "sohd='" + r["sohd"].ToString() + "' and ngayhd='" + r["ngayhd"].ToString() + "'"); if (r1 == null) { r2 = dsdn.Tables[0].NewRow(); r2["sohd"] = r["sohd"].ToString(); r2["ngayhd"] = r["ngayhd"].ToString(); r2["sophieu"] = i_soct.ToString(); //r["sophieu"].ToString(); r2["ngaysp"] = r["ngaysp"].ToString(); r2["sotien"] = decimal.Parse(r["sotien"].ToString()); dsdn.Tables[0].Rows.Add(r2); } else { dr = dsdn.Tables[0].Select("sohd='" + r["sohd"].ToString() + "' and ngayhd='" + r["ngayhd"].ToString() + "'"); if (dr.Length > 0) { dr[0]["sotien"] = decimal.Parse(dr[0]["sotien"].ToString()) + decimal.Parse(r["sotien"].ToString()); } } d_cothue += decimal.Parse(r["sotien"].ToString()); } } } } }