Example #1
0
        public string LayID(string tenBang)
        {
            string idnew = "";

            cl = new Server_Client.Client();
            // gán TCPclient
            this.client1 = cl.Connect(Luu.IP, Luu.Ports);
            // khởi tạo biến truyền vào với hàm khởi tạo
            Entities.LayID lid1 = new Entities.LayID("Select", tenBang);
            // khởi tạo mảng đối tượng để hứng giá trị
            Entities.LayID lid = new Entities.LayID();
            clientstream = cl.SerializeObj(this.client1, "LayID", lid1);
            // đổ mảng đối tượng vào datagripview
            lid = (Entities.LayID)cl.DeserializeHepper(clientstream, lid1);
            if (lid != null)
            {
                Common.Utilities a = new Common.Utilities();
                idnew = a.ProcessID(lid.ID);
            }
            else
            {
                if (lid == null)
                {
                    idnew = "TT_0001";
                }
            }
            return(idnew);
        }
Example #2
0
        /// <summary>
        /// Select Bảng
        /// </summary>
        /// <returns></returns>
        public object Select(Entities.LayID lid1)
        {
            Sql = new Constants.Sql();
            string sql = Sql.LayID;
            Connection conn = new Connection();
            SqlConnection cn = conn.openConnection();
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.Parameters.Add("@table", SqlDbType.NVarChar, 50).Value = lid1.TenBang;
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Fix 14/01/2013
            string phandau = string.Empty;
            string max = "0";
            while (dr.Read())
            {
                string[] temp = dr["ID"].ToString().Split('_');
                if (string.IsNullOrEmpty(phandau)) phandau = temp[0];
                if (max.Equals("0")) max = temp[1];
                try
                {
                    int ss = int.Parse(temp[1]);
                    int _max = int.Parse(max);
                    max = _max < ss ? temp[1] : max;
                }
                catch { }
            }
            Entities.LayID arrC = new Entities.LayID();
            arrC.ID = phandau + "_" + max;

            if (string.IsNullOrEmpty(phandau)) return null;
            //End Fix 14/01/2013

            ////Insert Category into ArrayList
            //ArrayList arr = new ArrayList();
            //while (dr.Read())
            //{
            //    Entities.LayID lid = new Entities.LayID();
            //    lid.ID = dr["ID"].ToString();
            //    arr.Add(lid);
            //}
            //int n = arr.Count;
            //if (n == 0) return null;

            //Entities.LayID arrC = new Entities.LayID();
            //for (int i = 0; i < n; i++)
            //{
            //    arrC = (Entities.LayID)arr[i];
            //}

            ////Giai phong bo nho
            //arr = null;
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn = null;
            conn = null;
            return arrC;
        }
Example #3
0
 public string ProIddtkh(string tenBang)
 {
     try
     {
         cl = new Server_Client.Client();
         // gán TCPclient
         Client1 = cl.Connect(Luu.IP, Luu.Ports);
         // khởi tạo biến truyền vào với hàm khởi tạo
         LayID lid1 = new LayID("Select", tenBang);
         // khởi tạo mảng đối tượng để hứng giá trị
         LayID lid = new LayID();
         Clientstrem = cl.SerializeObj(Client1, "LayID", lid1);
         // đổ mảng đối tượng vào datagripview
         lid = (LayID)cl.DeserializeHepper(Clientstrem, lid);
         if (lid == null)
             return "DTKH_0001";
         Common.Utilities a = new Common.Utilities();
         string idnew = a.ProcessID(lid.ID);
         return idnew;
     }
     catch { return ""; }
 }
Example #4
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 #5
0
 /// <summary>
 /// tu tang ID
 /// </summary>
 private void getID(string table)
 {
     try
     {
         Entities.LayID top = new Entities.LayID();
         cl = new Server_Client.Client();
         this.client = cl.Connect(Luu.IP, Luu.Ports);
         top = new Entities.LayID("Select", table);
         clientstrem = cl.SerializeObj(this.client, "LayID", top);
         Entities.LayID ddh = new Entities.LayID();
         ddh = (Entities.LayID)cl.DeserializeHepper(clientstrem, ddh);
         client.Close();
         clientstrem.Close();
         if (ddh != null)
         {
             string chuoi = ddh.ID.ToString();
             Common.Utilities com = new Common.Utilities();
             makiemtra = com.ProcessID(chuoi);
         }
         else
         { makiemtra = "HDN_0001"; }
     }
     catch (Exception ex)
     {
         string s = ex.Message;
         makiemtra = "HDN_0001";
     }
 }
 public string LayID(string tenBang)
 {
     string idnew="";
     cl = new Server_Client.Client();
     // gán TCPclient
     this.client1 = cl.Connect(Luu.IP, Luu.Ports);
     // khởi tạo biến truyền vào với hàm khởi tạo
     Entities.LayID lid1 = new Entities.LayID("Select", tenBang);
     // khởi tạo mảng đối tượng để hứng giá trị
     Entities.LayID lid = new Entities.LayID();
     clientstream = cl.SerializeObj(this.client1, "LayID", lid1);
     // đổ mảng đối tượng vào datagripview
     lid = (Entities.LayID)cl.DeserializeHepper(clientstream, lid1);
     if (lid != null)
     {
         Common.Utilities a = new Common.Utilities();
         idnew = a.ProcessID(lid.ID);
     }
     else
     {
         if (lid == null)
         {
             idnew = "NV_0001";
         }
     }
     return idnew;
 }
Example #7
0
 public string ProMaQuyDoi(string tenBang)
 {
     try
     {
         string idnew;
         Server_Client.Client cl = new Server_Client.Client();
         // gán TCPclient
         this.tcpClient = cl.Connect(Luu.IP, Luu.Ports);
         // khởi tạo biến truyền vào với hàm khởi tạo
         Entities.LayID lid1 = new Entities.LayID("Select", tenBang);
         // khởi tạo mảng đối tượng để hứng giá trị
         Entities.LayID lid = new Entities.LayID();
         networkStream = cl.SerializeObj(this.tcpClient, "LayID", lid1);
         // đổ mảng đối tượng vào datagripview
         lid = (Entities.LayID)cl.DeserializeHepper(networkStream, lid);
         if (lid == null)
         {
             return "QDDVT_0001";
         }
         Common.Utilities a = new Common.Utilities();
         idnew = a.ProcessID(lid.ID);
         return idnew;
     }
     finally { }
 }
Example #8
0
        public string LayID(string tenBang)
        {
            string idnew = "";
            Server_Client.Client client = new Server_Client.Client();
            this.tcpClient = client.Connect(Luu.IP, Luu.Ports);
            Entities.LayID lid1 = new Entities.LayID("Select", tenBang);
            Entities.LayID lid = new Entities.LayID();
            networkStream = client.SerializeObj(this.tcpClient, "LayID", lid1);
            lid = (Entities.LayID)client.DeserializeHepper(networkStream, lid);

            if (lid == null)
            {
                idnew = "CNG_0001";
            }
            else
            {
                Common.Utilities a = new Common.Utilities();
                idnew = a.ProcessID(lid.ID);
            }
            return idnew;
        }
Example #9
0
        /// <summary>
        /// Select Bảng
        /// </summary>
        /// <returns></returns>
        public object Select(Entities.LayID lid1)
        {
            Sql = new Constants.Sql();
            string        sql  = Sql.LayID;
            Connection    conn = new Connection();
            SqlConnection cn   = conn.openConnection();
            SqlCommand    cmd  = new SqlCommand(sql, cn);

            cmd.Parameters.Add("@table", SqlDbType.NVarChar, 50).Value = lid1.TenBang;
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            //Fix 14/01/2013
            string phandau = string.Empty;
            string max     = "0";

            while (dr.Read())
            {
                string[] temp = dr["ID"].ToString().Split('_');
                if (string.IsNullOrEmpty(phandau))
                {
                    phandau = temp[0];
                }
                if (max.Equals("0"))
                {
                    max = temp[1];
                }
                try
                {
                    int ss   = int.Parse(temp[1]);
                    int _max = int.Parse(max);
                    max = _max < ss ? temp[1] : max;
                }
                catch { }
            }
            Entities.LayID arrC = new Entities.LayID();
            arrC.ID = phandau + "_" + max;

            if (string.IsNullOrEmpty(phandau))
            {
                return(null);
            }
            //End Fix 14/01/2013

            ////Insert Category into ArrayList
            //ArrayList arr = new ArrayList();
            //while (dr.Read())
            //{
            //    Entities.LayID lid = new Entities.LayID();
            //    lid.ID = dr["ID"].ToString();
            //    arr.Add(lid);
            //}
            //int n = arr.Count;
            //if (n == 0) return null;

            //Entities.LayID arrC = new Entities.LayID();
            //for (int i = 0; i < n; i++)
            //{
            //    arrC = (Entities.LayID)arr[i];
            //}

            ////Giai phong bo nho
            //arr = null;
            cmd.Connection.Dispose();
            cn.Close();
            conn.closeConnection();
            cn   = null;
            conn = null;
            return(arrC);
        }