/// <summary>
 /// lay hang hoa theo ma tra lai nha cung cap
 /// </summary>
 /// <param name="truyen"></param>
 public Entities.LayHangHoaTheoMaKhachHangTraLai[] LayHangHoaTheoMaTraLaiNhaCungCap(Entities.TruyenGiaTri truyen)
 {
     Entities.LayHangHoaTheoMaKhachHangTraLai[] arrC = null;
     try
     {
         string sql = "exec sp_LayHangHoaTheoMaTraLaiNhaCungCap @MaTraLaiNhaCungCap";
         conn = new Connection();
         cn   = conn.openConnection();
         cmd  = new SqlCommand(sql, cn);
         cmd.Parameters.Add("MaTraLaiNhaCungCap", SqlDbType.VarChar, 20).Value = truyen.Giatritruyen;
         dr  = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         arr = new ArrayList();
         while (dr.Read())
         {
             Entities.LayHangHoaTheoMaKhachHangTraLai bang = new Entities.LayHangHoaTheoMaKhachHangTraLai();
             bang.Mahanghoa  = dr[0].ToString();
             bang.Tenhanghoa = dr[1].ToString();
             bang.Soluong    = int.Parse(dr[2].ToString());
             bang.Giaban     = dr[3].ToString();
             string phantram  = "0";
             string chietkhau = "0";
             string tong      = "0";
             if (Double.Parse(dr[4].ToString()) == 0)
             {
                 tong      = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
                 chietkhau = tong;
             }
             else
             {
                 phantram  = dr[4].ToString();
                 tong      = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
                 chietkhau = new Common.Utilities().FormatMoney(Double.Parse(tong) - ((Double.Parse(phantram) / 100 * Double.Parse(dr[3].ToString())) * int.Parse(dr[2].ToString())));
             }
             bang.Phantramchietkhau = phantram;
             bang.Thuegiatrigiatang = dr[5].ToString();
             bang.Chietkhau         = chietkhau;
             bang.Tongtien          = tong;
             arr.Add(bang);
         }
         int n = arr.Count;
         if (n == 0)
         {
             arrC = null;
         }
         arrC = new Entities.LayHangHoaTheoMaKhachHangTraLai[n];
         for (int i = 0; i < n; i++)
         {
             arrC[i] = (Entities.LayHangHoaTheoMaKhachHangTraLai)arr[i];
         }
     }
     catch (Exception ex)
     { string s = ex.Message.ToString(); arrC = null; }
     finally
     {
         cmd.Connection.Dispose();
         cn.Close();
         conn.closeConnection();
     }
     return(arrC);
 }
Example #2
0
 private void XuLy()
 {
     try
     {
         lay = new Common.Utilities();
         ServerConfig config = lay.ReadConfig();
         Luu.Server = "" + config.Server;
         Luu.IP     = "" + config.Ip;
         Luu.Ports  = Convert.ToInt32(0 + config.Port);
         if (config.Server == "client")
         {
             this.Hide();
             frmSQL fr = new frmSQL();
             fr.Show();
         }
         else
         {
             if (config.Server == "server")
             {
                 server     = new Server_Client.Server(Luu.Ports);
                 Luu.maychu = server;
                 this.Hide();
                 frmSQL fr = new frmSQL();
                 fr.Show();
             }
             else
             {
                 timer1.Stop();
                 count    = 0;
                 RunCount = 0;
                 frmServerConfig frm = new frmServerConfig();
                 frm.ShowDialog();
                 timer1.Start();
             }
         }
     }
     catch (Exception ex)
     { string s = ex.Message.ToString(); Application.Exit(); }
 }
Example #3
0
        public bool Update(Entities.SoDuCongNo[] sdcn)
        {
            int soluong = 0;

            Entities.SoDuCongNo[] hienthi = Select();
            // nếu obj null
            int year1  = 0;
            int month1 = 0;

            if (hienthi == null)
            {
                hienthi = new SoDuCongNo[0];
            }
            else
            {
                bool k1 = false;
                Entities.SoDuCongNo[] sdc = new SoDuCongNo[hienthi.Length];
                // kiểm tra số dư hiện tại
                for (int i = 0; i < sdc.Length; i++)
                {
                    k1 = false;

                    int nam1   = sdcn[0].NgayKetChuyen.Year;
                    int thang1 = sdcn[0].NgayKetChuyen.Month;
                    if (nam1 == hienthi[i].NgayKetChuyen.Year && thang1 == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                    {
                        k1 = true;
                        break;
                    }
                }

                if (k1 == true)
                {
                    for (int i = 0; i < sdc.Length; i++)
                    {
                        if (sdcn[0].NgayKetChuyen.Year == hienthi[i].NgayKetChuyen.Year && sdcn[0].NgayKetChuyen.Month == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                        {
                            year1        = sdcn[0].NgayKetChuyen.Year;
                            month1       = sdcn[0].NgayKetChuyen.Month;
                            sdc[soluong] = hienthi[i];
                            soluong++;
                        }
                    }
                    hienthi = new SoDuCongNo[soluong];
                    for (int i = 0; i < soluong; i++)
                    {
                        hienthi[i] = sdc[i];
                    }
                }
                else
                {
                    for (int i = 0; i < sdc.Length; i++)
                    {
                        if (sdcn[0].NgayKetChuyen.Month != 1)
                        {
                            if (sdcn[0].NgayKetChuyen.Year == hienthi[i].NgayKetChuyen.Year && (sdcn[0].NgayKetChuyen.Month - 1) == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                            {
                                Convert.ToDateTime((hienthi[0].NgayKetChuyen.Month - 1).ToString() + "/01/" + (hienthi[0].NgayKetChuyen.Year).ToString());
                                year1        = hienthi[0].NgayKetChuyen.Year;
                                month1       = hienthi[0].NgayKetChuyen.Month - 1;
                                sdc[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        else
                        {
                            if ((sdcn[0].NgayKetChuyen.Year - 1) == hienthi[i].NgayKetChuyen.Year && 12 == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                            {
                                year1  = hienthi[0].NgayKetChuyen.Year;
                                month1 = 12;
                                hienthi[i].NgayKetChuyen = Convert.ToDateTime(12.ToString() + "/01/" + year1.ToString());
                                sdc[soluong]             = hienthi[i];
                                soluong++;
                            }
                        }
                    }
                    hienthi = new SoDuCongNo[soluong];
                    for (int i = 0; i < soluong; i++)
                    {
                        hienthi[i] = sdc[i];
                    }
                }
            }
            Entities.SoDuCongNo[] mangluu;
            int sotang = 0;

            // đếm số bản ghi tồn tại rồi
            for (int i = 0; i < hienthi.Length; i++)
            {
                if (hienthi[i].LoaiDoiTuong == sdcn[0].LoaiDoiTuong)
                {
                    if (sdcn[0].MaDoiTuong != null)
                    {
                        sotang++;
                    }
                }
            }

            if (hienthi.Length == 0)
            {
                mangluu = new SoDuCongNo[sotang];
            }
            else
            {
                mangluu = new SoDuCongNo[hienthi.Length];
            }
            sotang = 0;
            bool kt1 = true;

            // gán giá trị cho obj mangluu khởi tạo
            if (hienthi.Length == 0)
            {
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].LoaiDoiTuong == sdcn[0].LoaiDoiTuong)
                    {
                        mangluu[sotang] = hienthi[i];
                        sotang++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < hienthi.Length; i++)
                {
                    mangluu[i] = hienthi[i];
                }
            }
            bool kt = false;

            for (int i = 0; i < sdcn.Length; i++)
            {
                kt = false;
                for (int j = 0; j < mangluu.Length; j++)
                {
                    if (sdcn[i].MaDoiTuong == mangluu[j].MaDoiTuong && sdcn[0].LoaiDoiTuong == mangluu[j].LoaiDoiTuong)
                    {
                        kt = true;
                        break;
                    }
                }
                string         maSoDuCongNo = "";
                Entities.LayID b            = new LayID("", "SoDuCongNo");
                b = (Entities.LayID) new BizLogic.Lay_ID().Select(b);
                if (b == null)
                {
                    maSoDuCongNo = "SDCN_0001";
                }
                else
                {
                    maSoDuCongNo = new Common.Utilities().ProcessID(b.ID);
                }
                if (kt == true)
                {
                    sdcn[i].MaSoDuCongNo = hienthi[i].MaSoDuCongNo;
                    Update(sdcn[i]);
                    int nam          = sdcn[i].NgayKetChuyen.Year;
                    int thang        = sdcn[i].NgayKetChuyen.Month;
                    int namhientai   = 0;
                    int thanghientai = 0;
                    if (hienthi.Length == 0)
                    {
                        namhientai   = DateTime.Now.Year;
                        thanghientai = DateTime.Now.Month;
                    }
                    else
                    {
                        namhientai   = hienthi[0].NgayKetChuyen.Year;
                        thanghientai = hienthi[0].NgayKetChuyen.Month;
                    }
                    Entities.SoDuCongNo a;
                    if (nam == namhientai && thang == thanghientai)
                    {
                        if (thang == 12)
                        {
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        }
                        else
                        {
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        }
                    }
                    else
                    if (thanghientai == 12)
                    {
                        a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                    }
                    else
                    {
                        a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, DateTime.Now, "0", sdcn[i].LoaiDoiTuong, false);
                    }

                    Insert(a);
                }
                else
                {
                    int nam          = sdcn[i].NgayKetChuyen.Year;
                    int thang        = sdcn[i].NgayKetChuyen.Month;
                    int namhientai   = DateTime.Now.Year;
                    int thanghientai = DateTime.Now.Month;
                    Entities.SoDuCongNo a;
                    if (sdcn[0].MaDoiTuong != null)
                    {
                        //a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, "0", Convert.ToDateTime(thang + "/01/" + nam), sdcn[i].SoDuCuoiKy, sdcn[i].LoaiDoiTuong, true);
                        a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, "0", new DateTime(nam, thang, 1), sdcn[i].SoDuCuoiKy, sdcn[i].LoaiDoiTuong, true);
                        Insert(a);
                        //if (nam == namhientai && thang == thanghientai)
                        //{
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //}
                        //else
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, DateTime.Now, "0", sdcn[i].LoaiDoiTuong, false);

                        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, new DateTime(nam, thang, 1).AddMonths(1), "0", sdcn[i].LoaiDoiTuong, false);
                        Insert(a);
                    }
                    else
                    {              //Có rồi thì update ngày kết chuyển = DateTime.Now
                        a = new SoDuCongNo(hienthi[i].MaSoDuCongNo, hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, "0", DateTime.Now, hienthi[i].SoDuDauKy, hienthi[i].LoaiDoiTuong, true);
                        Update(a); //gán số dư cuối kỳ, trạng thái = 1 where mã số dư công nợ, loại đối tượng
                        //if (nam == namhientai && thang == thanghientai)
                        //{
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //}
                        //else
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai).ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, DateTime.Now, "0", hienthi[i].LoaiDoiTuong, false);

                        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, new DateTime(nam, thang, 1).AddMonths(1), "0", hienthi[i].LoaiDoiTuong, false);
                        Insert(a);
                    }
                }
            }
            return(true);
        }
 /// <summary>
 /// lay hang hoa theo ma khach hang tra lai
 /// </summary>
 /// <param name="lay"></param>
 /// <returns></returns>
 //public Entities.LayHangHoaTheoMaKhachHangTraLai[] sp_LayHangHoaTheoMaKhachHangTraLai(Entities.TruyenGiaTri lay)
 //{
 //    Entities.LayHangHoaTheoMaKhachHangTraLai[] arrC = null;
 //    try
 //    {
 //        string sql = "exec sp_LayHangHoaTheoMaKhachHangTraLai @MaKhachHangTraLai,@LoaiHoaDon";
 //        conn = new Connection();
 //        cn = conn.openConnection();
 //        cmd = new SqlCommand(sql, cn);
 //        cmd.Parameters.Add("MaKhachHangTraLai", SqlDbType.VarChar, 20).Value = lay.Giatritruyen;
 //        cmd.Parameters.Add("LoaiHoaDon", SqlDbType.VarChar, 20).Value = lay.Giatrithuhai;
 //        dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
 //        arr = new ArrayList();
 //        while (dr.Read())
 //        {
 //            Entities.LayHangHoaTheoMaKhachHangTraLai bang = new Entities.LayHangHoaTheoMaKhachHangTraLai();
 //            bang.Mahanghoa = dr[0].ToString();
 //            bang.Tenhanghoa = dr[1].ToString();
 //            bang.Soluong = int.Parse(dr[2].ToString());
 //            bang.Giaban = dr[3].ToString();
 //            string phantram = "0";
 //            string chietkhau = "0";
 //            string tong = "0";
 //            if (Double.Parse(dr[4].ToString()) == 0)
 //            {
 //                tong = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
 //                chietkhau = tong;
 //            }
 //            else
 //            {
 //                phantram = dr[4].ToString();
 //                tong = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
 //                chietkhau = new Common.Utilities().FormatMoney(Double.Parse(tong) - ((Double.Parse(phantram) / 100 * Double.Parse(dr[3].ToString())) * int.Parse(dr[2].ToString())));
 //            }
 //            bang.Phantramchietkhau = phantram;
 //            bang.Thuegiatrigiatang = dr[5].ToString();
 //            bang.Chietkhau = chietkhau;
 //            bang.Tongtien = tong;
 //            arr.Add(bang);
 //        }
 //        int n = arr.Count;
 //        if (n == 0) { arrC= null; }
 //        arrC = new Entities.LayHangHoaTheoMaKhachHangTraLai[n];
 //        for (int i = 0; i < n; i++)
 //        {
 //            arrC[i] = (Entities.LayHangHoaTheoMaKhachHangTraLai)arr[i];
 //        }
 //    }
 //    catch (Exception ex)
 //    { string s = ex.Message.ToString(); arrC = null; }
 //    finally
 //    {
 //        cmd.Connection.Dispose();
 //        cn.Close();
 //        conn.closeConnection();
 //    }
 //    return arrC;
 //}
 public Entities.LayHangHoaTheoMaKhachHangTraLai[] sp_LayHangHoaTheoMaKhachHangTraLai(Entities.TruyenGiaTri lay)
 {
     Entities.LayHangHoaTheoMaKhachHangTraLai[] arrC = null;
     try
     {
         string sql = "exec sp_LayHangHoaTheoMaKhachHangTraLai @MaKhachHangTraLai,@MaKhachHang,@MaHDBanHang";
         conn = new Connection();
         cn = conn.openConnection();
         cmd = new SqlCommand(sql, cn);
         cmd.Parameters.Add("MaKhachHangTraLai", SqlDbType.VarChar, 20).Value = lay.Giatritruyen;
         cmd.Parameters.Add("MaKhachHang", SqlDbType.VarChar, 20).Value = lay.Giatrithuhai;
         cmd.Parameters.Add("MaHDBanHang", SqlDbType.VarChar, 20).Value = lay.Giatriba;
         dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         arr = new ArrayList();
         while (dr.Read())
         {
             Entities.LayHangHoaTheoMaKhachHangTraLai bang = new Entities.LayHangHoaTheoMaKhachHangTraLai();
             bang.Mahanghoa = dr[0].ToString();
             bang.Tenhanghoa = dr[1].ToString();
             bang.Soluong = int.Parse(dr[2].ToString());
             bang.Giaban = dr[3].ToString();
             string phantram = "0";
             string chietkhau = "0";
             string tong = "0";
             if (Double.Parse(dr[4].ToString()) == 0)
             {
                 tong = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
                 chietkhau = tong;
             }
             else
             {
                 phantram = dr[4].ToString();
                 tong = new Common.Utilities().FormatMoney(int.Parse(dr[2].ToString()) * Double.Parse(dr[3].ToString()));
                 chietkhau = new Common.Utilities().FormatMoney(Double.Parse(tong) - ((Double.Parse(phantram) / 100 * Double.Parse(dr[3].ToString())) * int.Parse(dr[2].ToString())));
             }
             bang.Phantramchietkhau = phantram;
             bang.Thuegiatrigiatang = dr[5].ToString();
             bang.Chietkhau = chietkhau;
             bang.Tongtien = tong;
             arr.Add(bang);
         }
         int n = arr.Count;
         if (n == 0) { arrC = null; }
         arrC = new Entities.LayHangHoaTheoMaKhachHangTraLai[n];
         for (int i = 0; i < n; i++)
         {
             arrC[i] = (Entities.LayHangHoaTheoMaKhachHangTraLai)arr[i];
         }
     }
     catch (Exception ex)
     { string s = ex.Message.ToString(); arrC = null; }
     finally
     {
         cmd.Connection.Dispose();
         cn.Close();
         conn.closeConnection();
     }
     return arrC;
 }
Example #5
0
        public bool Update(Entities.SoDuCongNo[] sdcn)
        {
            int soluong = 0;
            Entities.SoDuCongNo[] hienthi = Select();
            // nếu obj null
            int year1 = 0;
            int month1 = 0;
            if (hienthi == null)
            {
                hienthi = new SoDuCongNo[0];
            }
            else
            {
                bool k1 = false;
                Entities.SoDuCongNo[] sdc = new SoDuCongNo[hienthi.Length];
                // kiểm tra số dư hiện tại
                for (int i = 0; i < sdc.Length; i++)
                {
                    k1 = false;

                    int nam1 = sdcn[0].NgayKetChuyen.Year;
                    int thang1 = sdcn[0].NgayKetChuyen.Month;
                    if (nam1 == hienthi[i].NgayKetChuyen.Year && thang1 == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                    {
                        k1 = true;
                        break;
                    }
                }

                if (k1 == true)
                {
                    for (int i = 0; i < sdc.Length; i++)
                    {
                        if (sdcn[0].NgayKetChuyen.Year == hienthi[i].NgayKetChuyen.Year && sdcn[0].NgayKetChuyen.Month == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                        {
                            year1 = sdcn[0].NgayKetChuyen.Year;
                            month1 = sdcn[0].NgayKetChuyen.Month;
                            sdc[soluong] = hienthi[i];
                            soluong++;
                        }
                    }
                    hienthi = new SoDuCongNo[soluong];
                    for (int i = 0; i < soluong; i++)
                    {
                        hienthi[i] = sdc[i];
                    }
                }
                else
                {
                    for (int i = 0; i < sdc.Length; i++)
                    {
                        if (sdcn[0].NgayKetChuyen.Month != 1)
                        {
                            if (sdcn[0].NgayKetChuyen.Year == hienthi[i].NgayKetChuyen.Year && (sdcn[0].NgayKetChuyen.Month - 1) == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                            {
                                Convert.ToDateTime((hienthi[0].NgayKetChuyen.Month - 1).ToString() + "/01/" + (hienthi[0].NgayKetChuyen.Year).ToString());
                                year1 = hienthi[0].NgayKetChuyen.Year;
                                month1 = hienthi[0].NgayKetChuyen.Month-1;
                                sdc[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                        else
                        {
                            if ((sdcn[0].NgayKetChuyen.Year - 1) == hienthi[i].NgayKetChuyen.Year && 12 == hienthi[i].NgayKetChuyen.Month && sdcn[0].LoaiDoiTuong == hienthi[i].LoaiDoiTuong)
                            {
                                year1 = hienthi[0].NgayKetChuyen.Year;
                                month1 = 12;
                                hienthi[i].NgayKetChuyen = Convert.ToDateTime(12.ToString() + "/01/" + year1.ToString());
                                sdc[soluong] = hienthi[i];
                                soluong++;
                            }
                        }
                    }
                    hienthi = new SoDuCongNo[soluong];
                    for (int i = 0; i < soluong; i++)
                    {
                        hienthi[i] = sdc[i];
                    }
                }
            }
            Entities.SoDuCongNo[] mangluu;
            int sotang = 0;
            // đếm số bản ghi tồn tại rồi
            for (int i = 0; i < hienthi.Length; i++)
            {
                if (hienthi[i].LoaiDoiTuong == sdcn[0].LoaiDoiTuong)
                {
                    if (sdcn[0].MaDoiTuong != null)
                        sotang++;
                }
            }

            if (hienthi.Length == 0)
                mangluu = new SoDuCongNo[sotang];
            else
                mangluu = new SoDuCongNo[hienthi.Length];
            sotang = 0;
            bool kt1 = true;
            // gán giá trị cho obj mangluu khởi tạo
            if (hienthi.Length == 0)
            {
                for (int i = 0; i < hienthi.Length; i++)
                {
                    if (hienthi[i].LoaiDoiTuong == sdcn[0].LoaiDoiTuong)
                    {
                        mangluu[sotang] = hienthi[i];
                        sotang++;
                    }
                }
            }
            else
            {
                for (int i = 0; i < hienthi.Length; i++)
                {
                    mangluu[i] = hienthi[i];
                }
            }
            bool kt = false;
            for (int i = 0; i < sdcn.Length; i++)
            {
                kt = false;
                for (int j = 0; j < mangluu.Length; j++)
                {
                    if (sdcn[i].MaDoiTuong == mangluu[j].MaDoiTuong && sdcn[0].LoaiDoiTuong == mangluu[j].LoaiDoiTuong)
                    {
                        kt = true;
                        break;
                    }
                }
                string maSoDuCongNo = "";
                Entities.LayID b = new LayID("", "SoDuCongNo");
                b = (Entities.LayID)new BizLogic.Lay_ID().Select(b);
                if (b == null)
                {
                    maSoDuCongNo = "SDCN_0001";
                }
                else
                {
                    maSoDuCongNo = new Common.Utilities().ProcessID(b.ID);
                }
                if (kt == true)
                {
                    sdcn[i].MaSoDuCongNo = hienthi[i].MaSoDuCongNo;
                    Update(sdcn[i]);
                    int nam = sdcn[i].NgayKetChuyen.Year;
                    int thang = sdcn[i].NgayKetChuyen.Month;
                    int namhientai=0;
                    int thanghientai=0;
                    if (hienthi.Length == 0)
                    {
                        namhientai = DateTime.Now.Year;
                        thanghientai = DateTime.Now.Month;
                    }
                    else
                    {
                        namhientai = hienthi[0].NgayKetChuyen.Year;
                        thanghientai = hienthi[0].NgayKetChuyen.Month;
                    }
                    Entities.SoDuCongNo a;
                    if (nam == namhientai && thang == thanghientai)
                    {
                        if (thang == 12)
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        else
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                    }
                    else
                        if (thanghientai == 12)
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        else
                            a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, DateTime.Now, "0", sdcn[i].LoaiDoiTuong, false);

                    Insert(a);
                }
                else
                {
                    int nam = sdcn[i].NgayKetChuyen.Year;
                    int thang = sdcn[i].NgayKetChuyen.Month;
                    int namhientai = DateTime.Now.Year;
                    int thanghientai = DateTime.Now.Month;
                    Entities.SoDuCongNo a;
                    if (sdcn[0].MaDoiTuong != null)
                    {
                        //a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, "0", Convert.ToDateTime(thang + "/01/" + nam), sdcn[i].SoDuCuoiKy, sdcn[i].LoaiDoiTuong, true);
                        a = new SoDuCongNo(maSoDuCongNo, sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, "0", new DateTime(nam, thang, 1), sdcn[i].SoDuCuoiKy, sdcn[i].LoaiDoiTuong, true);
                        Insert(a);
                        //if (nam == namhientai && thang == thanghientai)
                        //{
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //}
                        //else
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai).ToString()), "0", sdcn[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, DateTime.Now, "0", sdcn[i].LoaiDoiTuong, false);

                        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), sdcn[i].MaDoiTuong, sdcn[i].TenDoiTuong, sdcn[i].DiaChi, sdcn[i].SoDuCuoiKy, new DateTime(nam, thang, 1).AddMonths(1), "0", sdcn[i].LoaiDoiTuong, false);
                        Insert(a);
                    }
                    else
                    {//Có rồi thì update ngày kết chuyển = DateTime.Now
                        a = new SoDuCongNo(hienthi[i].MaSoDuCongNo, hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, "0", DateTime.Now, hienthi[i].SoDuDauKy, hienthi[i].LoaiDoiTuong, true);
                        Update(a);  //gán số dư cuối kỳ, trạng thái = 1 where mã số dư công nợ, loại đối tượng
                        //if (nam == namhientai && thang == thanghientai)
                        //{
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime("01/01/" + (namhientai + 1).ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime((thang + 1).ToString() + "/01/" + namhientai.ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //}
                        //else
                        //    if (thang == 12)
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, Convert.ToDateTime(thang.ToString() + "/01/" + (namhientai).ToString()), "0", hienthi[i].LoaiDoiTuong, false);
                        //    else
                        //        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, DateTime.Now, "0", hienthi[i].LoaiDoiTuong, false);

                        a = new SoDuCongNo(new Common.Utilities().ProcessID(maSoDuCongNo), hienthi[i].MaDoiTuong, hienthi[i].TenDoiTuong, hienthi[i].DiaChi, hienthi[i].SoDuDauKy, new DateTime(nam, thang, 1).AddMonths(1), "0", hienthi[i].LoaiDoiTuong, false);
                        Insert(a);
                    }
                }
            }
            return true;
        }
Example #6
0
        private void XuLy()
        {
            try
            {

                lay = new Common.Utilities();
                ServerConfig config = lay.ReadConfig();
                Luu.Server = "" + config.Server;
                Luu.IP = "" + config.Ip;
                Luu.Ports = Convert.ToInt32(0 + config.Port);
                if (config.Server == "client")
                {
                    this.Hide();
                    frmSQL fr = new frmSQL();
                    fr.Show();
                }
                else
                {
                    if (config.Server == "server")
                    {
                        server = new Server_Client.Server(Luu.Ports);
                        Luu.maychu = server;
                        this.Hide();
                        frmSQL fr = new frmSQL();
                        fr.Show();
                    }
                    else
                    {
                        timer1.Stop();
                        count = 0;
                        RunCount = 0;
                        frmServerConfig frm = new frmServerConfig();
                        frm.ShowDialog();
                        timer1.Start();
                    }
                }
            }
            catch (Exception ex)
            { string s = ex.Message.ToString(); Application.Exit(); }
        }