using System; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.DAL.MsCtInitialBalanceDAL; using DSWeb.MvcShipping.Models.MsCtInitialBalance; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Comm.Cookie; using HcUtility.Comm; using HcUtility.Core; using System.Collections.Generic; using DSWeb.MvcShipping.DAL.MsBaseInfoDAL; using DSWeb.EntityDA; using DSWeb.Areas.CommMng.DAL; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsCtInitialBalanceController : Controller { public ActionResult Index() { return View(); } public ActionResult Edit() { return View(); } public ContentResult GetData(string condition) { MsCtInitialBalance head = MsCtInitialBalanceDAL.GetData(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"])); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } public ContentResult isSave(string condition) { DBResult result = MsCtInitialBalanceDAL.isSave(condition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #region 保存 public ContentResult Save(string dataHead, string dataRJZ, string dataDZD) { if (Convert.ToString(Session["COMPANYID"]).Trim() == "" || Convert.ToString(Session["USERID"]).Trim() == "" || Convert.ToString(Session["CODENAME"]).Trim() == "" || Convert.ToString(Session["SHOWNAME"]).Trim() == "" || Convert.ToString(Session["DEPTNAME"]).Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } // T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var headData = JsonConvert.Deserialize(dataHead.Replace("}", ",") + dataRJZ.Replace("{", "").Replace("}", ",") + dataDZD.Replace("{", "")); string sCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(Convert.ToString(Session["USERID"])); string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(Convert.ToString(Session["USERID"]).Trim()); string sCwACCDATE = BasicDataRefDAL.GetCwACCDATE(Convert.ToString(Session["USERID"]).Trim()); #region 默认值 if (headData.CURRENCY.ToString() != "RMB") { string sSQL = "select isnull((SELECT top 1 DEFAULTRATE=isnull((select top 1 BEGRATE from cw_currency_rate where LINKGID=code_currency.GID and ISDELETE=0 and ACCDATE= '" + sCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "'),DEFAULTRATE) from code_currency WITH(NOLOCK) where CODENAME='" + headData.CURRENCY.ToString() + "'),1) as DEFAULTRATE";// and CORPID='" + Convert.ToString(Session["COMPANYID"]) + "' Decimal dFCYEXRATE = Decimal.Parse(T_ALL_DA.GetStrSQL("DEFAULTRATE", sSQL)); // headData.AMTYEARBLC_D = Decimal.Parse((headData.QTYYEARBLC_D * dFCYEXRATE).ToString("F2")); } else { headData.AMTYEARBLC_D = headData.QTYYEARBLC_D; } headData.QTYYEARBLC_DH = headData.QTYYEARBLC_D + headData.QTYYEARCR_D - headData.QTYYEARDR_D; headData.QTYYEARBLC_BH = headData.QTYYEARBLC_B + headData.QTYYEARDR_B - headData.QTYYEARCR_B; headData.STARTGID = sCtSTARTGID.Trim();//启用账套GID headData.CORPID = Convert.ToString(Session["COMPANYID"]);//分公司代码 headData.CREATEUSER = Convert.ToString(Session["USERID"]);//创建人gid headData.CREATETIME = DateTime.Now;//创建时间 headData.MODIFIEDUSER = Convert.ToString(Session["USERID"]);//最后一次更新操作人GID headData.MODIFIEDTIME = DateTime.Now;//最后一次更改时间 if (headData.GID.ToString().Trim() == "*") { headData.GID = Guid.NewGuid().ToString();//唯一编码 headData.DbOperationType = DbOperationType.DbotIns; } else { headData.DbOperationType = DbOperationType.DbotUpd; headData.ModelUIStatus = "E"; } #endregion var modb = new ModelObjectDB(); DBResult result = modb.Save(headData); if (result.Message.ToString().IndexOf("重复") > -1) { result.Message = "注意:重复数据,不予以保存!"; } else { if (result.Success) { //插入更新总账表 MsCtInitialBalanceDAL.onCtGenlegAccitems(headData, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"])); } } string sCondition = "GID='" + headData.GID.ToString() + "'"; var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = MsCtInitialBalanceDAL.GetData(sCondition, Convert.ToString(Session["COMPANYID"]), Convert.ToString(Session["USERID"])) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion // } }