public ActionResult Create(FormCollection collection) { DAL.z_parameter dal_z_parameter = new DAL.z_parameter(); DAL.m_worker dal_m_worker = new DAL.m_worker(); try { Models.z_user session_model_z_user = (Models.z_user)ViewBag.model_z_user; ViewBag.area_list = dal_z_parameter.GetModelList("地区"); ViewBag.company_list = dal_z_parameter.GetModelList("分公司"); // TODO: Add insert logic here string B_NAME = collection["B_NAME"].Trim(); string B_GENDER = collection["B_GENDER"]; string B_TEL = collection["B_TEL"].Trim(); string B_ADDRESS = collection["B_ADDRESS"].Trim(); string B_ID_CARD = collection["B_ID_CARD"].Trim(); string B_CREATE_AREA_ID = collection["B_CREATE_AREA_ID"]; string B_EXPIRY_DATA = collection["B_EXPIRY_DATA"]; string W_WORK_AREA_ID = collection["W_WORK_AREA_ID"]; string W_IS_DELIVERY = collection["W_IS_DELIVERY"]; string W_DELIVERY_DATA = collection["W_DELIVERY_DATA"]; string W_IS_PASS_INTERVIEW = collection["W_IS_PASS_INTERVIEW"]; string W_INTERVIEW_DATA = collection["W_INTERVIEW_DATA"]; string W_IS_ONBOARD = collection["W_IS_ONBOARD"]; string W_ONBOARD_DATA = collection["W_ONBOARD_DATA"]; string W_IS_RESIGNATION = collection["W_IS_RESIGNATION"]; string W_RESIGNATION_DATA = collection["W_RESIGNATION_DATA"]; string A_GRADUATE_DATA = collection["A_GRADUATE_DATA"]; string A_CENSUS = collection["A_CENSUS"].Trim(); string A_EDU_BACKGROUND = collection["A_EDU_BACKGROUND"].Trim(); string A_HOME_TEL = collection["A_HOME_TEL"].Trim(); string A_HOME_ADDRESS = collection["A_HOME_ADDRESS"].Trim(); string COMMENTS = collection["COMMENTS"]; if (B_NAME == "" || B_GENDER == null || B_TEL == "" || B_CREATE_AREA_ID == "" || B_EXPIRY_DATA == "") { ViewBag.message = "新建失败,标红星的字段不能为空或者不选"; return View(); } if (dal_m_worker.isWorkerDuplicate(B_NAME, B_TEL, B_ID_CARD, null)) { ViewBag.message = "新建失败,姓名为:" + B_NAME + ",并且联系方式为:" + B_TEL + " 的工友已经存在。请在工友库中查找。"; return View(); } Models.m_worker model_m_worker = new Models.m_worker(); model_m_worker.ID = Guid.NewGuid(); model_m_worker.B_NAME = B_NAME; model_m_worker.B_GENDER = B_GENDER; model_m_worker.B_TEL = B_TEL; model_m_worker.B_ADDRESS = B_ADDRESS; model_m_worker.B_ID_CARD = B_ID_CARD; model_m_worker.B_CREATE_AREA_ID = new Guid(B_CREATE_AREA_ID); model_m_worker.B_ASSOCIATED_USER_ID = session_model_z_user.ID; model_m_worker.B_ASSOCIATED_DATA = DateTime.Now; model_m_worker.B_EXPIRY_DATA = DateTime.Parse(B_EXPIRY_DATA); try { model_m_worker.W_WORK_AREA_ID = new Guid(W_WORK_AREA_ID); } catch { model_m_worker.W_WORK_AREA_ID = Guid.Empty; } try { model_m_worker.W_IS_DELIVERY = int.Parse(W_IS_DELIVERY); } catch { model_m_worker.W_IS_DELIVERY = null; } try { model_m_worker.W_DELIVERY_DATA = DateTime.Parse(W_DELIVERY_DATA); } catch { model_m_worker.W_DELIVERY_DATA = null; } try { model_m_worker.W_IS_PASS_INTERVIEW = int.Parse(W_IS_PASS_INTERVIEW); } catch { model_m_worker.W_IS_PASS_INTERVIEW = null; } try { model_m_worker.W_INTERVIEW_DATA = DateTime.Parse(W_INTERVIEW_DATA); } catch { model_m_worker.W_INTERVIEW_DATA = null; } try { model_m_worker.W_IS_ONBOARD = int.Parse(W_IS_ONBOARD); } catch { model_m_worker.W_IS_ONBOARD = null; } try { model_m_worker.W_ONBOARD_DATA = DateTime.Parse(W_ONBOARD_DATA); } catch { model_m_worker.W_ONBOARD_DATA = null; } try { model_m_worker.W_IS_RESIGNATION = int.Parse(W_IS_RESIGNATION); } catch { model_m_worker.W_IS_RESIGNATION = null; } try { model_m_worker.W_RESIGNATION_DATA = DateTime.Parse(W_RESIGNATION_DATA); } catch { model_m_worker.W_RESIGNATION_DATA = null; } try { model_m_worker.A_GRADUATE_DATA = DateTime.Parse(A_GRADUATE_DATA); } catch { model_m_worker.A_GRADUATE_DATA = null; } model_m_worker.A_CENSUS = A_CENSUS; model_m_worker.A_EDU_BACKGROUND = A_EDU_BACKGROUND; model_m_worker.A_HOME_TEL = A_HOME_TEL; model_m_worker.A_HOME_ADDRESS = A_HOME_ADDRESS; model_m_worker.STATUS = Common.Variables.WORKER_STATUS_IN_POOL; model_m_worker.COMMENTS = COMMENTS; model_m_worker.CREATE_USER_ID = session_model_z_user.ID; model_m_worker.CREATE_DATETIME = DateTime.Now; model_m_worker.UPDATE_USER_ID = session_model_z_user.ID; model_m_worker.UPDATE_DATETIME = DateTime.Now; model_m_worker.DELETE_FLG = "0"; dal_m_worker.Add(model_m_worker); return RedirectToAction("Index", new { message = HttpUtility.UrlEncode("新建成功") }); } catch { ViewBag.message = "新建失败"; return View(); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Models.m_worker GetModel(string B_NAME, Guid B_ASSOCIATED_USER_ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 TT.*, T2.VALUE AS B_CREATE_AREA, T3.VALUE AS W_WORK_AREA, U2.LAST_NAME AS B_ASSOCIATED_USER, U3.LAST_NAME AS CREATE_USER,U4.LAST_NAME AS UPDATE_USER from m_worker as TT"); strSql.Append(" left join z_parameter AS T2 on TT.B_CREATE_AREA_ID = T2.ID "); strSql.Append(" left join z_parameter AS T3 on TT.W_WORK_AREA_ID = T3.ID "); strSql.Append(" left join z_user as U2 on TT.B_ASSOCIATED_USER_ID = U2.ID "); strSql.Append(" left join z_user as U3 on TT.CREATE_USER_ID = U3.ID "); strSql.Append(" left join z_user as U4 on TT.UPDATE_USER_ID = U4.ID"); strSql.Append(" where TT.B_ASSOCIATED_USER_ID=@B_ASSOCIATED_USER_ID and TT.B_NAME=@B_NAME "); SqlParameter[] parameters = { new SqlParameter("@B_ASSOCIATED_USER_ID", SqlDbType.UniqueIdentifier,16), new SqlParameter("@B_NAME", SqlDbType.NVarChar,50) }; parameters[0].Value = B_ASSOCIATED_USER_ID; parameters[1].Value = B_NAME; Models.m_worker model = new Models.m_worker(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count == 1) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
//我的工友,工友信息库导入 public String getWorkerImportList(DataTable dtInput, Boolean isPool, Guid sessionUserId) { DAL.z_parameter dal_z_parameter = new z_parameter(); DAL.z_user dal_z_user = new z_user(); DAL.m_worker dal_m_worker = new m_worker(); DataColumn Col = dtInput.Columns.Add("序号"); Col.SetOrdinal(0);// to put the column in position 0; dtInput.Columns.Add(new DataColumn("导入结果")); int newAddedItemNumber = 0; int updatedItemNumber = 0; int notImportedItemNumber = 0; for (int i = 0; i < dtInput.Rows.Count; i++) { string B_NAME = dtInput.Rows[i]["姓名"].ToString().Trim(); string B_GENDER = dtInput.Rows[i]["性别"].ToString().Trim(); string B_TEL = dtInput.Rows[i]["联系方式"].ToString().Trim(); string B_ADDRESS = dtInput.Rows[i]["联系地址"].ToString().Trim(); string B_CREATE_AREA = dtInput.Rows[i]["创建地区"].ToString().Trim(); string B_EXPIRY_DATA = dtInput.Rows[i]["到期时间"].ToString().Trim(); string B_ID_CARD = dtInput.Rows[i]["身份证号"].ToString().Trim(); //string B_ASSOCIATED_USER = dtInput.Rows[i]["管道"].ToString().Trim(); string W_WORK_AREA = dtInput.Rows[i]["工作地点"].ToString().Trim(); int STATUS = isPool ? Common.Variables.WORKER_STATUS_IN_POOL : Common.Variables.WORKER_STATUS_ON_HOLD; Guid B_CREATE_AREA_ID = dal_z_parameter.GetID("分公司", B_CREATE_AREA); Guid W_WORK_AREA_ID = dal_z_parameter.GetID("地区", W_WORK_AREA); Guid B_ASSOCIATED_USER_ID = sessionUserId; string inputResult = null; if ((B_CREATE_AREA != "" && B_CREATE_AREA_ID == Guid.Empty) || (W_WORK_AREA != "" && W_WORK_AREA_ID == Guid.Empty) ) { //Product or language are not found in the tool inputResult = "<span class='ImportError'>未导入。创建地点、或工作地点在系统中不存在。</span>"; notImportedItemNumber++; } else { Models.m_worker model_m_worker = dal_m_worker.GetModel(B_TEL, B_NAME); if (model_m_worker == null) { model_m_worker = new Models.m_worker(); model_m_worker.ID = Guid.NewGuid(); model_m_worker.B_NAME = B_NAME; model_m_worker.B_GENDER = B_GENDER; model_m_worker.B_TEL = B_TEL; model_m_worker.B_ADDRESS = B_ADDRESS; model_m_worker.B_ID_CARD = B_ID_CARD; model_m_worker.B_CREATE_AREA_ID = B_CREATE_AREA_ID; model_m_worker.B_ASSOCIATED_USER_ID = B_ASSOCIATED_USER_ID; model_m_worker.B_ASSOCIATED_DATA = DateTime.Now; model_m_worker.B_EXPIRY_DATA = DateTime.Parse(B_EXPIRY_DATA); model_m_worker.W_WORK_AREA_ID = W_WORK_AREA_ID; model_m_worker.STATUS = STATUS; model_m_worker.CREATE_USER_ID = sessionUserId; model_m_worker.CREATE_DATETIME = DateTime.Now; model_m_worker.UPDATE_USER_ID = sessionUserId; model_m_worker.UPDATE_DATETIME = DateTime.Now; model_m_worker.DELETE_FLG = "0"; dal_m_worker.Add(model_m_worker); //Can't find currently term with product and language in the tool. will add then. inputResult = "<span class='ImportNewItem'>导入。创建新工友。</span>"; newAddedItemNumber++; } else { inputResult = "<span class='ImportItemExist'>未导入。该联系方式的工友已存在。</span>"; notImportedItemNumber++; /* inputResult = "<span class='UpdateGlossary'>Imported. Update exist item.</span>"; updatedItemNumber++; model_g_glossary_items.DEFINITION = DEFINITION; model_g_glossary_items.TRANSLATED_TERM = REVISED_TRANSLATION; model_g_glossary_items.TRANSLATION_COMMENTS = TRANSLATION_COMMENTS; model_g_glossary_items.SYNCHRONOUS = 0; model_g_glossary_items.UPDATE_USER_ID = model_z_user.ID; model_g_glossary_items.UPDATE_DATETIME = DateTime.Now; model_g_glossary_items.DELETE_FLG = "0"; dal_g_glossary_items.Update(model_g_glossary_items); * */ } } //build the result column dtInput.Rows[i][0] = i + 1; dtInput.Rows[i][dtInput.Columns.Count - 1] = inputResult; } return "<br/><span><b>导入结果:</b></span>" + "<br/><span>总工友数: <b>" + dtInput.Rows.Count + "</b></span>" + " <span><b>" + newAddedItemNumber + "</b> 个工友新增。</span>" + " <span><b>" + updatedItemNumber + "</b> 个工友更新。</span>" + " <span><b>" + notImportedItemNumber + "</b> 个工友未导入。</span><br/>" + bulidTableHtml(dtInput); }
/// <summary> /// 得到一个对象实体 /// </summary> public Models.m_worker DataRowToModel(DataRow row) { Models.m_worker model = new Models.m_worker(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = new Guid(row["ID"].ToString()); } if (row["B_NAME"] != null) { model.B_NAME = row["B_NAME"].ToString(); } if (row["B_GENDER"] != null) { model.B_GENDER = row["B_GENDER"].ToString(); } if (row["B_TEL"] != null) { model.B_TEL = row["B_TEL"].ToString(); } if (row["B_ADDRESS"] != null) { model.B_ADDRESS = row["B_ADDRESS"].ToString(); } if (row["B_ID_CARD"] != null) { model.B_ID_CARD = row["B_ID_CARD"].ToString(); } if (row["B_CREATE_AREA_ID"] != null && row["B_CREATE_AREA_ID"].ToString() != "") { model.B_CREATE_AREA_ID = new Guid(row["B_CREATE_AREA_ID"].ToString()); } if (row["B_ASSOCIATED_USER_ID"] != null && row["B_ASSOCIATED_USER_ID"].ToString() != "") { model.B_ASSOCIATED_USER_ID = new Guid(row["B_ASSOCIATED_USER_ID"].ToString()); } if (row["B_ASSOCIATED_DATA"] != null && row["B_ASSOCIATED_DATA"].ToString() != "") { model.B_ASSOCIATED_DATA = DateTime.Parse(row["B_ASSOCIATED_DATA"].ToString()); } if (row["B_EXPIRY_DATA"] != null && row["B_EXPIRY_DATA"].ToString() != "") { model.B_EXPIRY_DATA = DateTime.Parse(row["B_EXPIRY_DATA"].ToString()); } if (row["W_WORK_AREA_ID"] != null && row["W_WORK_AREA_ID"].ToString() != "") { model.W_WORK_AREA_ID = new Guid(row["W_WORK_AREA_ID"].ToString()); } if (row["W_IS_DELIVERY"] != null && row["W_IS_DELIVERY"].ToString() != "") { model.W_IS_DELIVERY = int.Parse(row["W_IS_DELIVERY"].ToString()); } if (row["W_DELIVERY_DATA"] != null && row["W_DELIVERY_DATA"].ToString() != "") { model.W_DELIVERY_DATA = DateTime.Parse(row["W_DELIVERY_DATA"].ToString()); } if (row["W_IS_PASS_INTERVIEW"] != null && row["W_IS_PASS_INTERVIEW"].ToString() != "") { model.W_IS_PASS_INTERVIEW = int.Parse(row["W_IS_PASS_INTERVIEW"].ToString()); } if (row["W_INTERVIEW_DATA"] != null && row["W_INTERVIEW_DATA"].ToString() != "") { model.W_INTERVIEW_DATA = DateTime.Parse(row["W_INTERVIEW_DATA"].ToString()); } if (row["W_IS_ONBOARD"] != null && row["W_IS_ONBOARD"].ToString() != "") { model.W_IS_ONBOARD = int.Parse(row["W_IS_ONBOARD"].ToString()); } if (row["W_ONBOARD_DATA"] != null && row["W_ONBOARD_DATA"].ToString() != "") { model.W_ONBOARD_DATA = DateTime.Parse(row["W_ONBOARD_DATA"].ToString()); } if (row["W_IS_RESIGNATION"] != null && row["W_IS_RESIGNATION"].ToString() != "") { model.W_IS_RESIGNATION = int.Parse(row["W_IS_RESIGNATION"].ToString()); } if (row["W_RESIGNATION_DATA"] != null && row["W_RESIGNATION_DATA"].ToString() != "") { model.W_RESIGNATION_DATA = DateTime.Parse(row["W_RESIGNATION_DATA"].ToString()); } if (row["A_GRADUATE_DATA"] != null && row["A_GRADUATE_DATA"].ToString() != "") { model.A_GRADUATE_DATA = DateTime.Parse(row["A_GRADUATE_DATA"].ToString()); } if (row["A_CENSUS"] != null) { model.A_CENSUS = row["A_CENSUS"].ToString(); } if (row["A_EDU_BACKGROUND"] != null) { model.A_EDU_BACKGROUND = row["A_EDU_BACKGROUND"].ToString(); } if (row["A_HOME_TEL"] != null) { model.A_HOME_TEL = row["A_HOME_TEL"].ToString(); } if (row["A_HOME_ADDRESS"] != null) { model.A_HOME_ADDRESS = row["A_HOME_ADDRESS"].ToString(); } if (row["STATUS"] != null && row["STATUS"].ToString() != "") { model.STATUS = int.Parse(row["STATUS"].ToString()); } if (row["COMMENTS"] != null) { model.COMMENTS = row["COMMENTS"].ToString(); } if (row["CREATE_USER_ID"] != null && row["CREATE_USER_ID"].ToString() != "") { model.CREATE_USER_ID = new Guid(row["CREATE_USER_ID"].ToString()); } if (row["CREATE_DATETIME"] != null && row["CREATE_DATETIME"].ToString() != "") { model.CREATE_DATETIME = DateTime.Parse(row["CREATE_DATETIME"].ToString()); } if (row["UPDATE_USER_ID"] != null && row["UPDATE_USER_ID"].ToString() != "") { model.UPDATE_USER_ID = new Guid(row["UPDATE_USER_ID"].ToString()); } if (row["UPDATE_DATETIME"] != null && row["UPDATE_DATETIME"].ToString() != "") { model.UPDATE_DATETIME = DateTime.Parse(row["UPDATE_DATETIME"].ToString()); } if (row["DELETE_FLG"] != null) { model.DELETE_FLG = row["DELETE_FLG"].ToString(); } try { model.B_CREATE_AREA = row["B_CREATE_AREA"].ToString(); } catch { model.B_CREATE_AREA = ""; } try { model.W_WORK_AREA = row["W_WORK_AREA"].ToString(); } catch { model.W_WORK_AREA = ""; } try { model.B_ASSOCIATED_USER = row["B_ASSOCIATED_USER"].ToString(); } catch { model.B_ASSOCIATED_USER = ""; } try { model.CREATE_USER = row["CREATE_USER"].ToString(); } catch { model.CREATE_USER = ""; } try { model.UPDATE_USER = row["UPDATE_USER"].ToString(); } catch { model.UPDATE_USER = ""; } } return model; }