public DataSourceResult GetPage(DataSourceRequest request, string whereCondition) { List <SqlParameter> param = new List <SqlParameter>(); param.Add(new SqlParameter("@Page", request.Page)); param.Add(new SqlParameter("@PageSize", request.PageSize)); param.Add(new SqlParameter("@WhereCondition", whereCondition)); param.Add(new SqlParameter("@Sort", "")); DataTable dt = new SqlHelper().ExecuteQuery("p_GetAll_ListDNDQC", param); var lst = new List <CRM_Adv>(); foreach (DataRow row in dt.Rows) { var item = new CRM_Adv(); item.pk_adv = !row.IsNull("pk_adv") ? int.Parse(row["pk_adv"].ToString()) : 0; item.c_code = !row.IsNull("c_code") ? row["c_code"].ToString() : ""; item.fk_staff = !row.IsNull("fk_staff") ? int.Parse(row["fk_staff"].ToString()) : 0; item.c_vung_mien_nvkd = !row.IsNull("c_vung_mien_nvkd") ? int.Parse(row["c_vung_mien_nvkd"].ToString()) : 0; item.c_customer_name = !row.IsNull("c_customer_name") ? row["c_customer_name"].ToString() : ""; item.c_dot_order = !row.IsNull("c_dot_order") ? int.Parse(row["c_dot_order"].ToString()) : 0; item.tong_tien_hop_dong = !row.IsNull("tong_tien_hop_dong") ? double.Parse(row["tong_tien_hop_dong"].ToString()) : 0; item.c_don_gia_sau_ck = !row.IsNull("c_don_gia_sau_ck") ? double.Parse(row["c_don_gia_sau_ck"].ToString()) : 0; item.c_vung_mien = !row.IsNull("c_vung_mien") ? int.Parse(row["c_vung_mien"].ToString()) : 0; item.c_type = !row.IsNull("c_type") ? int.Parse(row["c_type"].ToString()) : 0; item.c_status = !row.IsNull("c_status") ? int.Parse(row["c_status"].ToString()) : 0; item.c_status_published = !row.IsNull("c_status_published") ? int.Parse(row["c_status_published"].ToString()) : 0; item.c_ngay_yc_duyet = !row.IsNull("c_ngay_yc_duyet") ? DateTime.Parse(row["c_ngay_yc_duyet"].ToString()) : DateTime.Parse("1900-01-01"); item.c_ngay_duyet = !row.IsNull("c_ngay_duyet") ? DateTime.Parse(row["c_ngay_duyet"].ToString()) : DateTime.Parse("1900-01-01"); item.fk_nguoi_duyet = !row.IsNull("c_nguoi_duyet") ? int.Parse(row["c_nguoi_duyet"].ToString()) : 0; item.c_publisher = !row.IsNull("c_publisher") ? row["c_publisher"].ToString() : ""; item.fk_staff_up_ocm = !row.IsNull("fk_staff_up_ocm") ? int.Parse(row["fk_staff_up_ocm"].ToString()) : -1; lst.Add(item); } request.Filters = null; DataSourceResult result = new DataSourceResult(); result.Data = lst; result.Total = dt.Rows.Count > 0 ? Convert.ToInt32(dt.Rows[0]["RowCount"]) : 0; return(result); }
public static object Save(CRM_Adv item, string username) { using (IDbConnection dbConn = ERPAPD.Helpers.OrmliteConnection.openConn()) { if (item != null) { try { var checkExits = dbConn.SingleOrDefault <CRM_Adv>("c_code= {0}", item.c_code); // check theo số hợp đồng if (checkExits == null) { var row = new CRM_Adv(); row.c_code = !string.IsNullOrEmpty(item.c_code) ? item.c_code.Trim() : ""; row.fk_staff = (item.fk_staff != -1) ? item.fk_staff : -1; row.c_input_date = !string.IsNullOrEmpty(item.c_input_date.ToString()) ? item.c_input_date : DateTime.Parse("1900-01-01"); row.c_status = -100; row.fk_nguoi_duyet = (item.fk_nguoi_duyet != -1) ? item.fk_nguoi_duyet : -1; row.c_ngay_duyet = !string.IsNullOrEmpty(item.c_ngay_duyet.ToString()) ? item.c_ngay_duyet : DateTime.Parse("1900-01-01"); row.c_ngay_yc_duyet = !string.IsNullOrEmpty(item.c_ngay_yc_duyet.ToString()) ? item.c_ngay_yc_duyet : DateTime.Parse("1900-01-01"); row.c_noi_dung_duyet = !string.IsNullOrEmpty(item.c_noi_dung_duyet) ? item.c_noi_dung_duyet.Trim() : ""; row.c_dinh_muc_bn = (item.c_dinh_muc_bn != 0) ? item.c_dinh_muc_bn : 0; row.c_dinh_muc_pr_goi = (item.c_dinh_muc_pr_goi != 0) ? item.c_dinh_muc_pr_goi : 0; row.c_dinh_muc_pr_thuong = (item.c_dinh_muc_pr_thuong != 0) ? item.c_dinh_muc_pr_thuong : 0; row.c_dinh_muc_cpm = (item.c_dinh_muc_pr_thuong != 0) ? item.c_dinh_muc_pr_thuong : 0; row.c_noi_dung_gui_duyet = !string.IsNullOrEmpty(item.c_noi_dung_gui_duyet) ? item.c_noi_dung_gui_duyet.Trim() : ""; row.c_note = !string.IsNullOrEmpty(item.c_note) ? item.c_note.Trim() : ""; row.c_noi_dung_xn_dang_dv = !string.IsNullOrEmpty(item.c_noi_dung_xn_dang_dv) ? item.c_noi_dung_xn_dang_dv.Trim() : ""; row.c_from_date = !string.IsNullOrEmpty(item.c_from_date.ToString()) ? item.c_from_date : DateTime.Parse("1900-01-01"); row.c_to_date = !string.IsNullOrEmpty(item.c_to_date.ToString()) ? item.c_to_date : DateTime.Parse("1900-01-01"); row.IsNew = 1; row.RowCreatedUser = username; row.RowUpdatedUser = ""; row.RowCreatedAt = DateTime.Now; row.RowUpdatedAt = DateTime.Parse("1900-01-01"); dbConn.Insert(row); long id = dbConn.GetLastInsertId(); return(new { success = true, message = "Save success!", pk_adv = id }); } else { checkExits.c_code = !string.IsNullOrEmpty(item.c_code) ? item.c_code.Trim() : ""; //checkExits.fk_staff = (item.fk_staff != 0) ? item.fk_staff : 0; //checkExits.c_input_date = !string.IsNullOrEmpty(item.c_input_date.ToString()) ? item.c_input_date : DateTime.Parse("1900-01-01"); //checkExits.c_status = (item.c_status != 0) ? item.c_status : 0; //checkExits.fk_nguoi_duyet = (item.fk_nguoi_duyet != 0) ? item.fk_nguoi_duyet : 0; //checkExits.c_ngay_duyet = !string.IsNullOrEmpty(item.c_ngay_duyet.ToString()) ? item.c_ngay_duyet : DateTime.Parse("1900-01-01"); //checkExits.c_ngay_yc_duyet = !string.IsNullOrEmpty(item.c_ngay_yc_duyet.ToString()) ? item.c_ngay_yc_duyet : DateTime.Parse("1900-01-01"); //checkExits.c_noi_dung_duyet = !string.IsNullOrEmpty(item.c_noi_dung_duyet) ? item.c_noi_dung_duyet.Trim() : ""; //checkExits.c_dinh_muc_bn = (item.c_dinh_muc_bn != 0) ? item.c_dinh_muc_bn : 0; //checkExits.c_dinh_muc_pr_goi = (item.c_dinh_muc_pr_goi != 0) ? item.c_dinh_muc_pr_goi : 0; //checkExits.c_dinh_muc_pr_thuong = (item.c_dinh_muc_pr_thuong != 0) ? item.c_dinh_muc_pr_thuong : 0; //checkExits.c_dinh_muc_cpm = (item.c_dinh_muc_pr_thuong != 0) ? item.c_dinh_muc_pr_thuong : 0; //checkExits.c_noi_dung_gui_duyet = !string.IsNullOrEmpty(item.c_noi_dung_gui_duyet) ? item.c_noi_dung_gui_duyet.Trim() : ""; //checkExits.c_note = !string.IsNullOrEmpty(item.c_note) ? item.c_note.Trim() : ""; //checkExits.c_noi_dung_xn_dang_dv = !string.IsNullOrEmpty(item.c_noi_dung_xn_dang_dv) ? item.c_noi_dung_xn_dang_dv.Trim() : ""; //checkExits.c_from_date = !string.IsNullOrEmpty(item.c_from_date.ToString()) ? item.c_from_date : DateTime.Parse("1900-01-01"); //checkExits.c_to_date = !string.IsNullOrEmpty(item.c_to_date.ToString()) ? item.c_to_date : DateTime.Parse("1900-01-01"); checkExits.RowUpdatedUser = username; checkExits.RowUpdatedAt = DateTime.Now; dbConn.Update(checkExits); return(new { success = true, message = "Save success!", pk_adv = checkExits.pk_adv }); } } catch (Exception e) { return(new { success = false, message = e.Message }); } } else { return(new { success = false, message = "Data is null!" }); } } }