Ejemplo n.º 1
0
 public static object Save(CRM_Adv_Duyet item, string username)
 {
     using (IDbConnection dbConn = ERPAPD.Helpers.OrmliteConnection.openConn())
     {
         if (item != null)
         {
             try
             {
                 //foreach (var item in items)
                 //{
                 var checkExits = dbConn.SingleOrDefault <CRM_Adv_Duyet>("fk_adv= {0} AND c_dot_order = {1}", item.fk_adv, item.c_dot_order);
                 if (checkExits == null)
                 {
                     var row = new CRM_Adv_Duyet();
                     row.fk_adv          = (item.fk_adv != 0) ? item.fk_adv : 0;
                     row.fk_staff        = (item.fk_staff != 0) ? item.fk_staff : 0;
                     row.c_type          = (item.c_type != -100) ? item.c_type : -100;
                     row.c_content       = !string.IsNullOrEmpty(item.c_content) ? item.c_content : "";
                     row.c_ngay_yc_duyet = !string.IsNullOrEmpty(item.c_ngay_yc_duyet.ToString()) ? DateTime.Parse(item.c_ngay_yc_duyet.ToString()) : DateTime.Parse("1900-01-01");
                     row.c_ngay_duyet    = !string.IsNullOrEmpty(item.c_ngay_duyet.ToString()) ? DateTime.Parse(item.c_ngay_duyet.ToString()) : DateTime.Parse("1900-01-01");
                     row.c_dot_order     = !string.IsNullOrEmpty(item.c_dot_order.ToString()) ? item.c_dot_order :0;
                     row.c_input_date    = !string.IsNullOrEmpty(item.c_input_date.ToString()) ? DateTime.Parse(item.c_input_date.ToString()) : DateTime.Parse("1900-01-01");
                     row.RowCreatedUser  = username;
                     row.RowUpdatedUser  = "";
                     row.RowCreatedAt    = DateTime.Now;
                     row.RowUpdatedAt    = DateTime.Parse("1900-01-01");
                     dbConn.Insert(row);
                 }
                 else
                 {
                     checkExits.fk_adv          = (item.fk_adv != 0) ? item.fk_adv : 0;
                     checkExits.fk_staff        = (item.fk_staff != 0) ? item.fk_staff : 0;
                     checkExits.c_type          = (item.c_type != -100) ? item.c_type : -100;
                     checkExits.c_content       = !string.IsNullOrEmpty(item.c_content) ? item.c_content : "";
                     checkExits.c_ngay_yc_duyet = !string.IsNullOrEmpty(item.c_ngay_yc_duyet.ToString()) ? DateTime.Parse(item.c_ngay_yc_duyet.ToString()) : DateTime.Parse("1900-01-01");
                     checkExits.c_ngay_duyet    = !string.IsNullOrEmpty(item.c_ngay_duyet.ToString()) ? DateTime.Parse(item.c_ngay_duyet.ToString()) : DateTime.Parse("1900-01-01");
                     checkExits.c_dot_order     = !string.IsNullOrEmpty(item.c_dot_order.ToString()) ? item.c_dot_order : 0;
                     checkExits.c_input_date    = !string.IsNullOrEmpty(item.c_input_date.ToString()) ? DateTime.Parse(item.c_input_date.ToString()) : DateTime.Parse("1900-01-01");
                     checkExits.RowUpdatedUser  = username;
                     checkExits.RowUpdatedAt    = DateTime.Now;
                     dbConn.Update(checkExits);
                 }
                 //}
                 long id = dbConn.GetLastInsertId();
                 return(new { success = true, message = "Save success!", pk_services = id });
             }
             catch (Exception e)
             {
                 return(new { success = false, message = e.Message });
             }
         }
         else
         {
             return(new { success = false, message = "Data is null!" });
         }
     }
 }
Ejemplo n.º 2
0
        public static object Save(IEnumerable <CRM_Adv_Services> items, int c_dot_order, string username)
        {
            using (IDbConnection dbConn = ERPAPD.Helpers.OrmliteConnection.openConn())
            {
                if (items != null)
                {
                    try
                    {
                        if (c_dot_order == 0)
                        {
                            var maxOrder = dbConn.QueryScalar <int>("SELECT MAX(c_dot_order) FROM CRM_Adv_Services WHERE fk_adv = '" + items.FirstOrDefault().fk_adv + "'") + 1;
                            c_dot_order = maxOrder;
                        }
                        long fk_adv = 0;

                        foreach (var item in items)
                        {
                            var checkExits = dbConn.SingleOrDefault <CRM_Adv_Services>("pk_services= {0}", item.pk_services);
                            if (checkExits == null)
                            {
                                var row = new CRM_Adv_Services();
                                fk_adv = item.fk_adv;

                                row.fk_adv              = (item.fk_adv != 0) ? item.fk_adv : 0;
                                row.c_type              = (item.c_type != 0) ? item.c_type : 0;
                                row.c_website           = !string.IsNullOrEmpty(item.c_website) ? item.c_website : "";
                                row.c_category          = !string.IsNullOrEmpty(item.c_category) ? item.c_category : "";
                                row.c_location          = !string.IsNullOrEmpty(item.c_location) ? item.c_location : "";
                                row.c_nature            = !string.IsNullOrEmpty(item.c_nature) ? item.c_nature : "";
                                row.c_ngay_len          = !string.IsNullOrEmpty(item.c_ngay_lenString) ? DateTime.Parse(item.c_ngay_lenString) : DateTime.Parse("1900-01-01");
                                row.c_ngay_xuong        = !string.IsNullOrEmpty(item.c_ngay_xuongString) ? DateTime.Parse(item.c_ngay_xuongString) : DateTime.Parse("1900-01-01");
                                row.c_so_luong          = !string.IsNullOrEmpty(item.c_so_luong) ? item.c_so_luong : "0";
                                row.c_size              = !string.IsNullOrEmpty(item.c_size) ? item.c_size : "";
                                row.c_format            = !string.IsNullOrEmpty(item.c_format) ? item.c_format : "";
                                row.c_don_gia           = (item.c_don_gia != 0) ? item.c_don_gia : 0;
                                row.c_km                = (item.c_km != 0) ? item.c_km : 0;
                                row.c_note              = !string.IsNullOrEmpty(item.c_note) ? item.c_note : "";
                                row.c_gio               = (item.c_gio != 0) ? item.c_gio : 0;
                                row.c_chiet_khau1       = (item.c_chiet_khau1 != 0) ? item.c_chiet_khau1 : 0;
                                row.c_chiet_khau2       = (item.c_chiet_khau2 != 0) ? item.c_chiet_khau2 : 0;
                                row.c_chiet_khau3       = (item.c_chiet_khau3 != 0) ? item.c_chiet_khau3 : 0;
                                row.c_vung_mien         = (item.c_vung_mien != 0) ? item.c_vung_mien : 0;
                                row.c_ngay_tra_tien     = !string.IsNullOrEmpty(item.c_ngay_tra_tienString) ? DateTime.Parse(item.c_ngay_tra_tienString) : DateTime.Parse("1900-01-01");
                                row.c_tien_tra          = (item.c_tien_tra != 0) ? item.c_tien_tra : 0;
                                row.c_luy_ke_da_dang    = (item.c_luy_ke_da_dang != 0) ? item.c_luy_ke_da_dang : 0;
                                row.c_dot_order         = c_dot_order;
                                row.c_status            = (item.c_status != 0) ? item.c_status : 0;
                                row.c_ngay_duyet        = !string.IsNullOrEmpty(item.c_ngay_duyetString) ? DateTime.Parse(item.c_ngay_duyetString) : DateTime.Parse("1900-01-01");
                                row.c_label             = !string.IsNullOrEmpty(item.c_label) ? item.c_label : "";
                                row.c_input_date        = DateTime.Now;
                                row.c_edit_date         = DateTime.Parse("1900-01-01");
                                row.fk_staff_edit       = (item.fk_staff_edit != 0) ? item.fk_staff_edit : 0;
                                row.c_book_code         = !string.IsNullOrEmpty(item.c_book_code) ? item.c_book_code : "";
                                row.c_ngay_up_ocm       = DateTime.Parse("1900-01-01");
                                row.fk_staff_up_ocm     = -1;
                                row.c_kenh_qc           = !string.IsNullOrEmpty(item.c_kenh_qc) ? item.c_kenh_qc : "";
                                row.c_chuyen_muc_kenhqc = !string.IsNullOrEmpty(item.c_chuyen_muc_kenhqc) ? item.c_chuyen_muc_kenhqc : "";
                                row.c_vi_tri_kenhqc     = !string.IsNullOrEmpty(item.c_vi_tri_kenhqc) ? item.c_vi_tri_kenhqc : "";
                                row.IsNew               = 1;
                                row.c_don_gia_sau_ck    = (item.c_don_gia_sau_ck != 0) ? item.c_don_gia_sau_ck : 0;
                                row.RowCreatedUser      = username;
                                row.RowUpdatedUser      = "";
                                row.RowCreatedAt        = DateTime.Now;
                                row.RowUpdatedAt        = DateTime.Parse("1900-01-01");
                                dbConn.Insert(row);
                            }
                            else
                            {
                                fk_adv                      = item.fk_adv;
                                checkExits.fk_adv           = (item.fk_adv != 0) ? item.fk_adv : 0;
                                checkExits.c_type           = (item.c_type != 0) ? item.c_type : 0;
                                checkExits.c_website        = !string.IsNullOrEmpty(item.c_website) ? item.c_website : "";
                                checkExits.c_category       = !string.IsNullOrEmpty(item.c_category) ? item.c_category : "";
                                checkExits.c_location       = !string.IsNullOrEmpty(item.c_location) ? item.c_location : "";
                                checkExits.c_nature         = !string.IsNullOrEmpty(item.c_nature) ? item.c_nature : "";
                                checkExits.c_ngay_len       = !string.IsNullOrEmpty(item.c_ngay_lenString) ? DateTime.Parse(item.c_ngay_lenString) : checkExits.c_ngay_len;
                                checkExits.c_ngay_xuong     = !string.IsNullOrEmpty(item.c_ngay_xuongString) ? DateTime.Parse(item.c_ngay_xuongString) : checkExits.c_ngay_xuong;
                                checkExits.c_so_luong       = !string.IsNullOrEmpty(item.c_so_luong) ? item.c_so_luong : "0";
                                checkExits.c_size           = !string.IsNullOrEmpty(item.c_size) ? item.c_size : "";
                                checkExits.c_format         = !string.IsNullOrEmpty(item.c_format) ? item.c_format : "";
                                checkExits.c_don_gia        = (item.c_don_gia != 0) ? item.c_don_gia : 0;
                                checkExits.c_km             = (item.c_km != 0) ? item.c_km : 0;
                                checkExits.c_note           = !string.IsNullOrEmpty(item.c_note) ? item.c_note : "";
                                checkExits.c_gio            = (item.c_gio != 0) ? item.c_gio : 0;
                                checkExits.c_chiet_khau1    = (item.c_chiet_khau1 != 0) ? item.c_chiet_khau1 : 0;
                                checkExits.c_chiet_khau2    = (item.c_chiet_khau2 != 0) ? item.c_chiet_khau2 : 0;
                                checkExits.c_chiet_khau3    = (item.c_chiet_khau3 != 0) ? item.c_chiet_khau3 : 0;
                                checkExits.c_vung_mien      = (item.c_vung_mien != 0) ? item.c_vung_mien : 0;
                                checkExits.c_ngay_tra_tien  = !string.IsNullOrEmpty(item.c_ngay_tra_tienString) ? DateTime.Parse(item.c_ngay_tra_tienString) : checkExits.c_ngay_tra_tien;
                                checkExits.c_tien_tra       = (item.c_tien_tra != 0) ? item.c_tien_tra : 0;
                                checkExits.c_luy_ke_da_dang = (item.c_luy_ke_da_dang != 0) ? item.c_luy_ke_da_dang : 0;
                                checkExits.c_order          = (item.c_order != 0) ? item.c_order : 0;
                                checkExits.c_status         = (item.c_status != 0) ? item.c_status : 0;
                                checkExits.c_ngay_duyet     = !string.IsNullOrEmpty(item.c_ngay_duyetString) ? DateTime.Parse(item.c_ngay_duyetString) : checkExits.c_ngay_duyet;
                                checkExits.c_tien_tra       = (item.c_tien_tra != 0) ? item.c_tien_tra : 0;
                                checkExits.c_label          = !string.IsNullOrEmpty(item.c_label) ? item.c_label : "";
                                checkExits.c_edit_date      = DateTime.Now;
                                checkExits.fk_staff_edit    = (item.fk_staff_edit != 0) ? item.fk_staff_edit : 0;
                                checkExits.c_book_code      = !string.IsNullOrEmpty(item.c_book_code) ? item.c_book_code : "";
                                //checkExits.c_dot_order = (item.c_dot_order != 0) ? item.c_dot_order : 0;
                                //checkExits.c_ngay_up_ocm = !string.IsNullOrEmpty(item.c_ngay_up_ocmString) ? DateTime.Parse(item.c_ngay_up_ocmString) : checkExits.c_ngay_up_ocm;
                                //checkExits.fk_staff_up_ocm = (item.fk_staff_up_ocm != 0) ? item.fk_staff_up_ocm : 0;
                                checkExits.c_kenh_qc           = !string.IsNullOrEmpty(item.c_kenh_qc) ? item.c_kenh_qc : "";
                                checkExits.c_chuyen_muc_kenhqc = !string.IsNullOrEmpty(item.c_chuyen_muc_kenhqc) ? item.c_chuyen_muc_kenhqc : "";
                                checkExits.c_vi_tri_kenhqc     = !string.IsNullOrEmpty(item.c_vi_tri_kenhqc) ? item.c_vi_tri_kenhqc : checkExits.c_vi_tri_kenhqc;
                                checkExits.c_don_gia_sau_ck    = (item.c_don_gia_sau_ck != 0) ? item.c_don_gia_sau_ck : checkExits.c_don_gia_sau_ck;
                                checkExits.RowUpdatedUser      = username;
                                checkExits.RowUpdatedAt        = DateTime.Now;
                                dbConn.Update(checkExits);
                            }
                        }
                        long id    = dbConn.GetLastInsertId();
                        var  duyet = dbConn.Where <CRM_Adv_Duyet>(p => p.fk_adv == fk_adv && p.c_dot_order == c_dot_order).FirstOrDefault();
                        if (duyet == null)
                        {
                            CRM_Adv_Duyet n = new CRM_Adv_Duyet();
                            n.fk_adv          = fk_adv;
                            n.fk_staff        = -1;
                            n.c_type          = -100;
                            n.c_dot_order     = c_dot_order;
                            n.c_ngay_yc_duyet = DateTime.Parse("1900-01-01");
                            CRM_Adv_Duyet.Save(n, username);
                        }
                        return(new { success = true, message = "Save success!", pk_services = id, c_dot_order = c_dot_order });
                    }
                    catch (Exception e)
                    {
                        return(new { success = false, message = e.Message });
                    }
                }
                else
                {
                    return(new { success = false, message = "Data is null!" });
                }
            }
        }