Exemple #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblGridViewMsg.Text = "";
            try
            {
                using (GoldEntities context = new GoldEntities())
                {
                    foreach (GridViewRow gvRow in this.gv_CargoList.Rows)
                    {
                        CheckBox rowChk       = gvRow.FindControl("chkSaleStatus") as CheckBox;
                        Label    lblCargoCode = gvRow.FindControl("lblCargoCode") as Label;
                        if (rowChk != null && lblCargoCode != null)
                        {
                            string     cargoCode   = lblCargoCode.Text.Trim();
                            DAL.Cargos updateModel = (from r in context.Cargos where r.CargoCode == cargoCode select r).FirstOrDefault();
                            updateModel.SaleStatus = rowChk.Checked ? 1 : 0;
                        }
                    }

                    //使用隐式事务
                    int AffectRowsCount = context.SaveChanges();
                    lblGridViewMsg.Text = "保存成功[更新" + AffectRowsCount.ToString() + "条记录]";
                }
            }
            catch (Exception ex)
            {
                lblGridViewMsg.Text = "保存失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
            }
        }
Exemple #2
0
        protected void btnSaveRoot_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtRootCode.Text.Trim()))
            {
                lblrootMessage.Text = "代码不能为空!";
                return;
            }

            if (string.IsNullOrEmpty(txtRootName.Text.Trim()))
            {
                lblrootMessage.Text = "名称不能为空!";
                return;
            }

            using (var edm = new GoldEntities())
            {
                var tmp = edm.CreateObject <DataDict>();
                tmp.Name     = txtRootName.Text.Trim();
                tmp.Code     = txtRootCode.Text.Trim();
                tmp.Category = "root";
                tmp.Enabled  = true;

                edm.AddToDataDict(tmp);
                edm.SaveChanges();

                TreeNode node = new TreeNode();
                node.Value = tmp.Code;
                node.Text  = tmp.Name;
                TreeView1.Nodes.Add(node);

                txtRootCode.Text    = "";
                txtRootName.Text    = "";
                lblrootMessage.Text = "保存成功!";
            }
        }
Exemple #3
0
        /// <summary>
        /// 将从用友获取的DataTable数据保存到RFID系统
        /// </summary>
        /// <param name="dt">从用友获取的DataTable数据</param>
        /// <param name="msg">信息提示</param>
        /// <returns>true成功,false失败</returns>
        public override bool SaveToRFID(System.Data.DataTable dt, out string msg)
        {
            msg = "";
            try
            {
                string        convertMsg = "";
                List <Cargos> list       = GetModelFromDataTable(dt, out convertMsg);
                if (list.Count == 0)
                {
                    msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                    return(false);
                }
                else
                {
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查询系统中所有仓库编码
                        List <string> RFIDKeyList = (from r in context.Cargos select r.CargoCode).ToList <string>();
                        //NC数据集中与现有系统已重复的数据主键
                        List <int> delKeyList = new List <int>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (RFIDKeyList.Contains(list[i].CargoCode))
                            {
                                delKeyList.Add(i);//如果RFID系统中已存在此数据,则将索引加入待删除列表
                            }
                        }
                        delKeyList.Reverse();                //待删除索引逆序
                        foreach (int delIndex in delKeyList) //删除
                        {
                            list.RemoveAt(delIndex);
                        }

                        //若过滤后数据行为0,那么也认为保存成功并提示用户
                        if (list.Count == 0)
                        {
                            msg = "保存成功!影响行数:0。用友系统中商品资料数据已全部存在于RFID系统中。";
                            return(true);
                        }

                        //变量过滤后的实体集,将其加入数据库
                        foreach (Cargos newModel in list)
                        {
                            context.Cargos.AddObject(newModel);
                        }

                        //提交变更
                        int AffectRowsCount = context.SaveChanges();
                        msg = "保存成功!影响行数:" + AffectRowsCount.ToString();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "CargoInfo SaveToRFID方法出错", ex);
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// 新增按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddNew_Click(object sender, EventArgs e)
        {
            if (Page.IsValid == false)
            {
                return;
            }

            try
            {
                lblAddMsg.Text = "";
                string        whCode         = WebConfigHelper.Instance.GetAppSettingValue("DefaultWHCode");
                List <string> checkedDelList = GetCheckItemID();
                if (checkedDelList.Count <= 0)
                {
                    lblAddMsg.Text = "请先选中待设置的项";
                    //ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('请先在列表中选中待设置的项,填写要设置的安全库存量后再点击“保存”按钮');</script>");
                    return;
                }

                using (GoldEntities context = new GoldEntities())
                {
                    foreach (string checkCode in checkedDelList)
                    {
                        CargoSafeInventory existModel = (from r in context.CargoSafeInventory where r.CargoCode.Equals(checkCode) && r.WHCode.Equals(whCode) select r).FirstOrDefault();
                        if (existModel != null)
                        {
                            existModel.SafeInventory = int.Parse(tbxNewSafeNumber.Text);
                        }
                        else
                        {
                            CargoSafeInventory newObj = new CargoSafeInventory();
                            newObj.WHCode        = whCode;
                            newObj.CargoCode     = checkCode;
                            newObj.SafeInventory = int.Parse(tbxNewSafeNumber.Text);

                            context.CargoSafeInventory.AddObject(newObj);
                        }
                    }
                    int affectedRow = context.SaveChanges();
                    if (affectedRow > 0)
                    {
                        lblAddMsg.Text = "保存成功![已保存" + affectedRow.ToString() + "项]";
                    }
                    else
                    {
                        lblAddMsg.Text = "保存失败!";
                    }

                    GridViewBind();//删除后重新绑定数据
                }
            }
            catch (Exception ex)
            {
                lblAddMsg.Text = "保存失败!";
                //lblGridViewMsg.Text = "删除出现异常!详细信息:" + Utility.LogHelper.GetExceptionMsg(ex);
                LogHelper.WriteLog(LogHelper.LogLevel.Error, "安全库存量设置AddNew", ex);
            }
        }
Exemple #5
0
        /// <summary>
        /// 行命令触发前先清空界面消息提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gv_BinList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView senderGrid = sender as GridView;

            //更新或删除前对消息Label清空
            if (e.CommandName == "Edit" || e.CommandName == "Update" || e.CommandName == "Delete")
            {
                //lblGridViewMsg.Text = "";
                ClearTipMsgLabel();//清除提示信息
            }
            else if (e.CommandName == "MyDefineUpdate")
            {
                lblGridViewMsg.Text = "";
                if (senderGrid.EditIndex != -1)
                {
                    int editBinCode = (int)senderGrid.DataKeys[senderGrid.EditIndex].Value;
                    try
                    {
                        using (GoldEntities context = new GoldEntities())
                        {
                            PackageStatistic updateModel = (from r in context.PackageStatistic where r.PSID == editBinCode select r).FirstOrDefault();
                            string           msg         = "";
                            if (GetUpdateModel(ref updateModel, senderGrid.Rows[senderGrid.EditIndex], out msg) == false)
                            {
                                lblGridViewMsg.Text = msg;
                                DAL.CommonConvert.ShowMessageBox(this.Page, msg);
                                return;
                            }
                            else
                            {
                                int result = context.SaveChanges();
                                if (result > 0)
                                {
                                    lblGridViewMsg.Text = "更新成功!";
                                    DAL.CommonConvert.ShowMessageBox(this.Page, "更新成功!");
                                    senderGrid.EditIndex = -1;//取消编辑状态
                                }
                                else
                                {
                                    DAL.CommonConvert.ShowMessageBox(this.Page, "更新失败(影响行数为0)!");
                                    lblGridViewMsg.Text = "更新失败(影响行数为0)";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "更新失败!");
                        lblGridViewMsg.Text = "更新失败[" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
                    }
                }
            }
        }
Exemple #6
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         lblSaveMsg.Text = "";
         string outMsg = "";
         if (ViewState["EditType"].ToString() == "1")//新增Insert
         {
             DAL.StorePickAccount newModel = new StorePickAccount();
             bool getNewOK = GetNewModel(out newModel, out outMsg);
             if (getNewOK == false)
             {
                 lblSaveMsg.Text = "新增失败![" + outMsg + "]";
                 return;
             }
             using (GoldEntities context = new GoldEntities())
             {
                 context.StorePickAccount.AddObject(newModel);
                 int AffectRowsCount = context.SaveChanges();
                 lblSaveMsg.Text  = "保存成功";
                 btnSave.Enabled  = false;
                 btnSave.CssClass = "ButtonImageStyleEnableFalse";
             }
         }
         else//更新Update
         {
             using (GoldEntities context = new GoldEntities())
             {
                 int EditID = int.Parse(ViewState["EditID"].ToString());
                 DAL.StorePickAccount updateModel = (from r in context.StorePickAccount where r.StockPickAccountID == EditID select r).FirstOrDefault();
                 bool getUpdateOK = GetUpdateModel(ref updateModel, out outMsg);
                 if (getUpdateOK == false)
                 {
                     lblSaveMsg.Text = "更新失败![" + outMsg + "]";
                     return;
                 }
                 //context.WareHouse.Attach(updateModel);
                 int AffectRowsCount = context.SaveChanges();
                 lblSaveMsg.Text  = "保存成功";
                 btnSave.Enabled  = false;
                 btnSave.CssClass = "ButtonImageStyleEnableFalse";
             }
         }
     }
     catch (Exception ex)
     {
         lblSaveMsg.Text = "更新失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
     }
 }
Exemple #7
0
        protected void btnDelDept_Click(object sender, EventArgs e)
        {
            if (TreeView1.SelectedNode != null && string.IsNullOrEmpty(TreeView1.SelectedNode.Value) == false)
            {
                string msg = "";
                try
                {
                    string deptcode = lblCurrentDeptCode.Text;
                    string deptname = lblCurrentDeptName.Text;
                    if (deptcode == "root")
                    {
                        ShowMessageBox("顶级部门不可删除!");
                        return;
                    }
                    using (var edm = new GoldEntities())
                    {
                        Department query = (from p in edm.Department
                                            where p.DepartmentCode == deptcode
                                            select p).FirstOrDefault <Department>();
                        edm.Department.DeleteObject(query);
                        int affectRows = edm.SaveChanges();
                        msg = "部门[" + deptname + "]删除成功![影响行数" + affectRows.ToString() + "]";
                    }
                    ShowMessageBox(msg);

                    //删除成功后清除界面信息
                    lblCurrentDeptCode.Text = "";
                    lblCurrentDeptName.Text = "";
                    btnDelDept.Enabled      = false;
                    btnDelDept.CssClass     = "ButtonImageStyleEnableFalse";
                }
                catch (Exception ex)
                {
                    msg = "删除失败";
                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "删除部门信息出错!", ex);
                    ShowMessageBox(msg, ex);
                }
                //重新加载TreeView
                InitTree();
            }
            else
            {
                ShowMessageBox("请先点击选中左侧的部门,然后再点击此删除按钮!");
            }
        }
Exemple #8
0
 protected void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         lblSaveMsg.Text = "";
         string outMsg = "";
         if (ViewState["EditType"].ToString() == "1")//新增Insert
         {
             DAL.WareHouse newModel = new WareHouse();
             bool          getNewOK = GetNewModel(out newModel, out outMsg);
             if (getNewOK == false)
             {
                 lblSaveMsg.Text = "新增失败![" + outMsg + "]";
                 return;
             }
             using (GoldEntities context = new GoldEntities())
             {
                 context.WareHouse.AddObject(newModel);
                 int AffectRowsCount = context.SaveChanges();
                 lblSaveMsg.Text = "保存成功";
             }
         }
         else//更新Update
         {
             using (GoldEntities context = new GoldEntities())
             {
                 string        EditID      = ViewState["EditID"].ToString();
                 DAL.WareHouse updateModel = (from r in context.WareHouse where r.WHCode == EditID select r).FirstOrDefault();
                 bool          getUpdateOK = GetUpdateModel(ref updateModel, out outMsg);
                 if (getUpdateOK == false)
                 {
                     lblSaveMsg.Text = "更新失败![" + outMsg + "]";
                     return;
                 }
                 //context.WareHouse.Attach(updateModel);
                 int AffectRowsCount = context.SaveChanges();
                 lblSaveMsg.Text = "保存成功";
             }
         }
     }
     catch (Exception ex)
     {
         lblSaveMsg.Text = "更新失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
     }
 }
Exemple #9
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                lblCheckMsg.Text    = "";
                lblGridViewMsg.Text = "";
                List <string> checkedDelList = GetCheckItemID();
                if (checkedDelList.Count <= 0)
                {
                    //lblCheckMsg.Text = "请先选中待删除的项";
                    ShowMessageBox("请先选中待删除的项");
                    return;
                }

                using (GoldEntities context = new GoldEntities())
                {
                    foreach (string delCode in checkedDelList)
                    {
                        DAL.WareHouse delObject = (from r in context.WareHouse where r.WHCode.Equals(delCode) select r).FirstOrDefault();

                        context.DeleteObject(delObject);
                    }
                    int delRow = context.SaveChanges();
                    if (delRow > 0)
                    {
                        //lblCheckMsg.Text = "删除成功![已删除" + delRow.ToString() + "项]";
                        ShowMessageBox("删除成功![已删除" + delRow.ToString() + "项]");
                    }
                    else
                    {
                        //lblCheckMsg.Text = "删除失败!";
                        ShowMessageBox("删除失败!");
                    }

                    GridViewBind();//删除后重新绑定数据
                }
            }
            catch (Exception ex)
            {
                //lblCheckMsg.Text = "删除出现异常!";
                //lblGridViewMsg.Text = Utility.LogHelper.GetExceptionMsg(ex);
                ShowMessageBox("删除失败!", ex);
            }
        }
Exemple #10
0
        /// <summary>
        /// 多项删除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ClearTipMsgLabel();//清除提示信息

                List <int> checkedDelList = GetCheckItemID();
                if (checkedDelList.Count <= 0)
                {
                    lblCheckMsg.Text = "请先选中待删除的项";
                    DAL.CommonConvert.ShowMessageBox(this.Page, "请先选中待删除的项!");
                    return;
                }

                using (GoldEntities context = new GoldEntities())
                {
                    foreach (int delCode in checkedDelList)
                    {
                        PackageStatistic delObject = (from r in context.PackageStatistic where r.PSID.Equals(delCode) select r).FirstOrDefault();

                        context.DeleteObject(delObject);
                    }
                    int delRow = context.SaveChanges();
                    if (delRow > 0)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "删除成功![已删除" + delRow.ToString() + "项]");
                        lblCheckMsg.Text = "删除成功![已删除" + delRow.ToString() + "项]";
                    }
                    else
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "删除失败!");
                        lblCheckMsg.Text = "删除失败!";
                    }

                    //GridViewBind();//删除后重新绑定数据
                    gv_BinList.DataBind();
                }
            }
            catch (Exception ex)
            {
                DAL.CommonConvert.ShowMessageBox(this.Page, "删除失败!");
                lblGridViewMsg.Text = "删除失败[" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
            }
        }
Exemple #11
0
        private void InitTree()
        {
            TreeView1.Nodes.Clear();

            using (var edm = new GoldEntities())
            {
                var query = from p in edm.Department
                            where p.DepartmentCode == "root"
                            select p;

                Department root;
                if (query.Count <Department>() == 0)
                {
                    var tmp = edm.CreateObject <Department>();
                    tmp.DepartmentCode = "root";
                    tmp.DepartmentName = "深圳金币";
                    tmp.Parent         = "0";

                    edm.AddToDepartment(tmp);
                    edm.SaveChanges();

                    root = tmp;
                }
                else
                {
                    root = query.First();
                }

                TreeNode rootNode = new TreeNode();
                rootNode.Text  = root.DepartmentName;
                rootNode.Value = root.DepartmentCode;
                CreatChildNodes(rootNode, root, edm);
                TreeView1.Nodes.Add(rootNode);
                rootNode.ExpandAll();

                if (TreeView1.SelectedNode == null)
                {
                    rootNode.Select();
                    GridViewBind();//显示全部用户
                }
            }
        }
Exemple #12
0
        protected void btnSaveValue_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtValueCode.Text.Trim()))
            {
                lblMessage2.Text = "代码不能为空!";
                return;
            }

            if (string.IsNullOrEmpty(txtValueName.Text.Trim()))
            {
                lblMessage2.Text = "名称不能为空!";
                return;
            }


            using (var edm = new GoldEntities())
            {
                var tmp = edm.CreateObject <DataDict>();
                tmp.Name = txtValueName.Text.Trim();
                tmp.Code = txtValueCode.Text.Trim();
                int x;
                if (!string.IsNullOrEmpty(txtValueOrder.Text.Trim()) &&
                    int.TryParse(txtValueOrder.Text.Trim(), out x))
                {
                    tmp.Order = x;
                }

                tmp.Category = TreeView1.SelectedNode.Value;
                tmp.Enabled  = true;

                edm.AddToDataDict(tmp);
                edm.SaveChanges();

                GridView1.DataBind();

                txtValueCode.Text  = "";
                txtValueName.Text  = "";
                txtValueOrder.Text = "";
                lblMessage2.Text   = "保存成功!";
            }
        }
Exemple #13
0
        //删除行
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                List <string> checkedDelList = GetCheckItemID();
                if (checkedDelList.Count <= 0)
                {
                    lblGridViewMsg.Text = "请先选中待删除的项";
                    return;
                }

                using (GoldEntities tmp = new GoldEntities())
                {
                    foreach (string delCode in checkedDelList)
                    {
                        DAL.ShiftOrder delObject = (from r in tmp.ShiftOrder where r.OrderCode.Equals(delCode) select r).FirstOrDefault();

                        tmp.DeleteObject(delObject);
                    }
                    int delRow = tmp.SaveChanges();
                    if (delRow > 0)
                    {
                        lblGridViewMsg.Text = "删除成功![已删除" + delRow.ToString() + "项]";
                    }
                    else
                    {
                        lblGridViewMsg.Text = "删除失败!";
                    }

                    GridView1.DataBind();//删除后重新绑定数据
                }
            }
            catch (Exception ex)
            {
                lblGridViewMsg.Text = "删除失败[" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
            }
        }
Exemple #14
0
        /// <summary>
        /// 将从用友获取的DataTable数据保存到RFID系统
        /// </summary>
        /// <param name="dt">从用友获取的DataTable数据</param>
        /// <param name="msg">信息提示</param>
        /// <returns>true成功,false失败</returns>
        public override bool SaveToRFID(List <SalesOrder> list, out string msg)
        {
            msg = "";
            try
            {
                if (list.Count == 0)
                {
                    //msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                    return(false);
                }
                else
                {
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查询系统中所有采购订单编号
                        List <SalesOrder> RFIDKeyList = (from r in context.SalesOrder select r).ToList <SalesOrder>();
                        string            existNCcode = string.Empty;
                        List <SalesOrder> delList     = new List <SalesOrder>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            foreach (SalesOrder order in RFIDKeyList)
                            {
                                if (order.NCOrderCode == list[i].NCOrderCode && order.OrderStatus == 2)
                                {
                                    delList.Add(order);
                                    break;
                                }
                                else if (order.NCOrderCode == list[i].NCOrderCode)
                                {
                                    existNCcode += list[i].NCOrderCode + ",";
                                    break;
                                }
                            }
                        }

                        if (existNCcode != string.Empty)
                        {
                            existNCcode = existNCcode.Substring(0, existNCcode.Length - 1);
                            msg         = "保存失败!。用友系统中订单数据(" + existNCcode + ")存在于RFID系统中且已开始其他操作。";
                            return(false);
                        }

                        //删除数据库中原有的数据
                        if (delList.Count != 0)
                        {
                            foreach (SalesOrder sales in delList)
                            {
                                context.SalesOrder.DeleteObject(sales);
                                context.SaveChanges();
                            }
                        }

                        //其加入数据库
                        foreach (SalesOrder newModel in list)
                        {
                            //搜索对应的销售订单详细信息
                            List <SalesOrderDetail> lstSalesOrderDetail = new List <SalesOrderDetail>();
                            if (GetNCDataDetailJoinRFID(out lstSalesOrderDetail, out msg, newModel.NCOrderCode))
                            {
                                foreach (SalesOrderDetail detail in lstSalesOrderDetail)
                                {
                                    newModel.SalesOrderDetail.Add(detail);
                                }
                            }
                            else
                            {
                                return(false);
                            }

                            context.SalesOrder.AddObject(newModel);
                        }

                        //提交变更
                        int AffectRowsCount = context.SaveChanges();
                        msg = "保存成功!影响行数:" + AffectRowsCount.ToString();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "SalesOrder SaveToRFID方法出错", ex);
                msg = "SalesOrder SaveToRFID方法出错" + ex.Message;
                return(false);
            }
        }
Exemple #15
0
        /// <summary>
        /// 将从用友获取的DataTable数据保存到RFID系统
        /// </summary>
        /// <param name="dt">从用友获取的DataTable数据</param>
        /// <param name="msg">信息提示</param>
        /// <returns>true成功,false失败</returns>
        public override bool SaveToRFID(System.Data.DataTable dt, out string msg)
        {
            msg = "";
            try
            {
                string       convertMsg = "";
                List <Users> list       = GetModelFromDataTable(dt, out convertMsg);

                if (list == null)
                {
                    msg = "校验用友数据时出现异常!详细信息:" + convertMsg;
                    return(false);
                }
                else if (list.Count == 0)
                {
                    msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                    return(false);
                }
                else
                {
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查询系统中所有仓库编码
                        List <string> RFIDKeyList = (from r in context.Users select r.UserId).ToList <string>();
                        //NC数据集中与现有系统已重复的数据主键
                        List <int> delKeyList = new List <int>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (RFIDKeyList.Contains(list[i].UserId))
                            {
                                delKeyList.Add(i);//如果RFID系统中已存在此数据,则将索引加入待删除列表
                            }
                        }
                        delKeyList.Reverse();                //待删除索引逆序
                        foreach (int delIndex in delKeyList) //从用友系统中获取的用户信息若在RFID系统中已经存在,则从新增列表中删除掉
                        {
                            list.RemoveAt(delIndex);
                        }

                        //若过滤后数据行为0,那么也认为保存成功并提示用户
                        if (list.Count == 0)
                        {
                            msg = "保存成功!影响行数:0。用友系统中商品规格数据已全部存在于RFID系统中。";
                            return(true);
                        }


                        //变量过滤后的实体集,将其加入Gold数据库
                        foreach (Users newModel in list)
                        {
                            //加入到实体框架中
                            context.Users.AddObject(newModel);
                        }

                        //提交变更
                        int AffectRowsCount = context.SaveChanges();

                        try
                        {
                            if (AffectRowsCount > 0)
                            {
                                //变量过滤后的实体集,将其加入Aspnetdb数据库
                                foreach (Users newModel in list)
                                {
                                    //加入到aspnetdb中
                                    MembershipUser user      = Membership.CreateUser(newModel.UserId, "123456");
                                    string[]       userRoles = { "普通用户" };
                                    if (userRoles != null && userRoles.Count() > 0)
                                    {
                                        Roles.AddUserToRoles(newModel.UserId, userRoles);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "UserInfo SaveToRFID方法出错", ex);

                            if (AffectRowsCount > 0) //如果Gold数据库新增成功,但membership出错,那么将Gold中和membership中的的数据全都删除
                            {
                                //变量过滤后的实体集,将其加入数据库
                                foreach (Users newModel in list)
                                {
                                    Users delModel = (from r in context.Users where r.UserId == newModel.UserId select r).FirstOrDefault <Users>();
                                    if (delModel != null)//从实体框架中删除
                                    {
                                        context.Users.DeleteObject(delModel);
                                    }

                                    //从aspnetdb中删除
                                    if (Membership.GetUser(newModel.UserId) != null)
                                    {
                                        bool delResult = Membership.DeleteUser(newModel.UserId);//删除Membership中用户
                                    }
                                }
                                context.SaveChanges();//提交变更
                            }

                            msg = "保存失败!详细信息:" + LogHelper.GetExceptionMsg(ex);
                            return(false);
                        }

                        msg = "保存成功!影响行数:" + AffectRowsCount.ToString();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "UserInfo SaveToRFID方法出错", ex);
                return(false);
            }
        }
Exemple #16
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                lblSaveMsg.Text = "";
                string outMsg = "";
                if (ViewState["EditType"].ToString() == "1")//新增Insert
                {
                    StockCountingPlan          newModel   = new StockCountingPlan();
                    List <StockCountingDetail> ListDetail = new List <StockCountingDetail>();

                    bool getNewOK = GetNewModel(out newModel, out ListDetail, out outMsg);
                    if (getNewOK == false)
                    {
                        lblSaveMsg.Text = "新增失败![" + outMsg + "]";
                        return;
                    }
                    using (GoldEntities context = new GoldEntities())
                    {
                        //新增计划表
                        context.StockCountingPlan.AddObject(newModel);

                        //新增盘点表
                        foreach (StockCountingDetail sd in ListDetail)
                        {
                            context.StockCountingDetail.AddObject(sd);
                        }

                        int AffectRowsCount = context.SaveChanges();
                        lblSaveMsg.Text  = "保存成功![影响行数" + AffectRowsCount.ToString() + "]";
                        btnSave.Enabled  = false;
                        btnSave.CssClass = "ButtonImageStyleEnableFalse";
                    }
                }
                else//更新Update
                {
                    //更新时,先删除全部明细表的行,再新增所有本次选中的层位对应的明细行
                    using (GoldEntities context = new GoldEntities())
                    {
                        string EditID = ViewState["EditID"].ToString();

                        List <StockCountingDetail> OldListDetail = new List <StockCountingDetail>();
                        List <StockCountingDetail> ListDetail    = new List <StockCountingDetail>();

                        StockCountingPlan updateModel = (from r in context.StockCountingPlan where r.SCPCode == EditID select r).FirstOrDefault();
                        if (updateModel != null)
                        {
                            if (updateModel.SCPStatus.Value != (int)EnumData.SCPStatusEnum.Initial)
                            {
                                lblSaveMsg.Text = "更新失败![该盘点计划单不是初始状态,不能进行修改]";
                                return;
                            }

                            bool getUpdateOK = GetUpdateModel(ref updateModel, out ListDetail, out outMsg);
                            if (getUpdateOK == false)
                            {
                                lblSaveMsg.Text = "更新失败![" + outMsg + "]";
                                return;
                            }

                            OldListDetail = (from r in context.StockCountingDetail where r.SCPCode == updateModel.SCPCode select r).ToList <StockCountingDetail>();

                            //先删除旧有的明细行
                            foreach (StockCountingDetail del in OldListDetail)
                            {
                                context.StockCountingDetail.DeleteObject(del);
                            }

                            //再新增本次选中的明细行
                            foreach (StockCountingDetail add in ListDetail)
                            {
                                context.StockCountingDetail.AddObject(add);
                            }

                            int AffectRowsCount = context.SaveChanges();
                            lblSaveMsg.Text  = "保存成功![影响行数" + AffectRowsCount.ToString() + "]";
                            btnSave.Enabled  = false;
                            btnSave.CssClass = "ButtonImageStyleEnableFalse";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblSaveMsg.Text = "更新失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
            }
        }
Exemple #17
0
        //查看,编辑,删除
        protected void gv_CargoList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView senderGrid = sender as GridView;

            //更新或删除前对消息Label清空
            if (e.CommandName == "Edit" || e.CommandName == "Update" || e.CommandName == "Delete")
            {
                lblGridViewMsg.Text = "";
                //ClearTipMsgLabel();//清除提示信息
            }
            else if (e.CommandName == "ViewDetail")
            {
                GridViewRow drv        = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                Label       lblSCPCode = drv == null ? null : drv.FindControl("lblSCPCode") as Label;

                string EditID = lblSCPCode.Text;
                System.Text.StringBuilder url = new System.Text.StringBuilder("~/Query/StockCountingPlanView.aspx?");
                url.Append("EditID=");
                url.Append(EditID); //"~/BaseInfoSetting/WareHouseEdit.aspx?EditType=2";
                Response.Redirect(url.ToString());
            }
            else if (e.CommandName == "MyEdit")
            {
                GridViewRow drv        = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                Label       lblSCPCode = drv == null ? null : drv.FindControl("lblSCPCode") as Label;
                //QueryString中EditType 1为新增 2为编辑
                //QueryString中EditID 0表示不编辑 1表示编辑
                string EditID = lblSCPCode.Text;
                lblGridViewMsg.Text = "";

                System.Text.StringBuilder url = new System.Text.StringBuilder("~/Query/StockCountingPlanEdit.aspx?EditType=2");
                url.Append("&EditID=");
                url.Append(EditID); //"~/BaseInfoSetting/WareHouseEdit.aspx?EditType=2";
                Response.Redirect(url.ToString());
            }
            else if (e.CommandName == "MyDelete")
            {
                try
                {
                    GridViewRow drv        = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值
                    Label       lblSCPCode = drv == null ? null : drv.FindControl("lblSCPCode") as Label;
                    //QueryString中EditType 1为新增 2为编辑
                    //QueryString中EditID 0表示不编辑 1表示编辑
                    string EditID = lblSCPCode.Text;


                    lblGridViewMsg.Text = "";

                    //更新时,先删除全部明细表的行,再新增所有本次选中的层位对应的明细行
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查出待删除的计划单
                        StockCountingPlan delModel = (from r in context.StockCountingPlan where r.SCPCode == EditID select r).FirstOrDefault();
                        //查出待删除的明细单
                        List <StockCountingDetail> delDetailList = (from r in context.StockCountingDetail where r.SCPCode == EditID select r).ToList <StockCountingDetail>();

                        //删除明细行
                        foreach (StockCountingDetail d in delDetailList)
                        {
                            context.StockCountingDetail.DeleteObject(d);
                        }
                        //删除计划单
                        context.StockCountingPlan.DeleteObject(delModel);

                        int AffectRowsCount = context.SaveChanges();
                        lblGridViewMsg.Text = "盘点计划单[" + EditID + "]删除成功![影响行数" + AffectRowsCount.ToString() + "]";

                        GridViewBind();//删除完成后重新绑定盘点计划单
                    }
                }
                catch (Exception ex)
                {
                    lblGridViewMsg.Text = "删除失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
                }


                //lblGridViewMsg.Text = "已删除";
            }
        }
Exemple #18
0
        /// <summary>
        /// 行命令触发前先清空界面消息提示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gv_BinList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            GridView senderGrid = sender as GridView;

            //更新或删除前对消息Label清空
            if (e.CommandName == "Edit" || e.CommandName == "Update" || e.CommandName == "Delete")
            {
                //lblGridViewMsg.Text = "";
                ClearTipMsgLabel();//清除提示信息
            }
            else if (e.CommandName == "MyDefineUpdate")
            {
                lblGridViewMsg.Text = "";
                if (senderGrid.EditIndex != -1)
                {
                    string editBinCode = senderGrid.DataKeys[senderGrid.EditIndex].Value.ToString();
                    try
                    {
                        using (GoldEntities context = new GoldEntities())
                        {
                            StorageBin updateModel = (from r in context.StorageBin where r.BinCode == editBinCode select r).FirstOrDefault();
                            string     msg         = "";
                            if (GetUpdateModel(ref updateModel, senderGrid.Rows[senderGrid.EditIndex], out msg) == false)
                            {
                                lblGridViewMsg.Text = msg;
                                return;
                            }
                            else
                            {
                                int result = context.SaveChanges();
                                if (result > 0)
                                {
                                    lblGridViewMsg.Text  = "更新成功!";
                                    senderGrid.EditIndex = -1;//取消编辑状态
                                }
                                else
                                {
                                    lblGridViewMsg.Text = "更新失败(影响行数为0)";
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        lblGridViewMsg.Text = "更新失败[" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
                    }
                }
            }
            else
            {
                if (e.CommandName == "TagAlarmStart" || e.CommandName == "TagAlarmStop")
                {
                    string shortMsg  = "";
                    string detailMsg = "";
                    string binTagID  = "";
                    bool   result    = false;

                    GridViewRow drv                   = ((GridViewRow)(((Button)(e.CommandSource)).Parent.Parent));             //此得出的值是表示那行被选中的索引值
                    Label       lblRowBinTagID        = drv == null ? null : drv.FindControl("lblRowBinTagID") as Label;
                    Label       lblRowTagTestShortMsg = drv == null ? null : drv.FindControl("lblRowTagTestShortMsg") as Label; //非编辑状态下 显示标签编码的控件
                    TextBox     tbxRowBinTagID        = drv == null ? null : drv.FindControl("tbxRowBinTagID") as TextBox;      //编辑状态下 显示标签编码的控件

                    //先清空提示
                    lblRowTagTestShortMsg.Text = "";
                    lblGridViewMsg.Text        = "";


                    if (lblRowBinTagID == null && tbxRowBinTagID == null)
                    {
                        lblGridViewMsg.Text = "获取列表中层位标签标签信息失败!";
                        shortMsg            = lblGridViewMsg.Text;
                        return;
                    }
                    else
                    {
                        if (senderGrid.EditIndex == -1 && lblRowBinTagID != null)//非编辑态下获取标签编码
                        {
                            binTagID = lblRowBinTagID.Text.Trim();
                        }
                        else if (senderGrid.EditIndex != -1 && tbxRowBinTagID != null)//编辑态下获取标签编码
                        {
                            binTagID = tbxRowBinTagID.Text.Trim();
                        }
                    }

                    if (e.CommandName == "TagAlarmStart")
                    {
                        result = StartOrStopAlarm(binTagID, true, out shortMsg, out detailMsg);
                    }
                    else if (e.CommandName == "TagAlarmStop")
                    {
                        result = StartOrStopAlarm(binTagID, false, out shortMsg, out detailMsg);
                    }

                    lblRowTagTestShortMsg.Text = shortMsg;
                    lblGridViewMsg.Text        = detailMsg;

                    gv_BinList.DataBind();//亮灯和关灯后手持机服务会改标签数据库字段状态,所以这里刷新数据源
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// 将从用友获取的DataTable数据保存到RFID系统
        /// </summary>
        /// <param name="dt">从用友获取的DataTable数据</param>
        /// <param name="msg">信息提示</param>
        /// <returns>true成功,false失败</returns>
        public override bool SaveToRFID(List <StockIn> list, out string msg)
        {
            msg = "";
            try
            {
                //string convertMsg = "";
                if (list.Count == 0)
                {
                    //msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                    return(false);
                }
                else
                {
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查询系统中所有采购订单编号
                        List <StockIn> RFIDKeyList = (from r in context.StockIn select r).ToList <StockIn>();

                        string         existNCcode = string.Empty;
                        List <StockIn> delList     = new List <StockIn>();
                        for (int i = 0; i < list.Count; i++)
                        {
                            foreach (StockIn si in RFIDKeyList)
                            {
                                //0-初始态,1-已保存,2-已提交,3-撤销中,4-已撤销,5-已完成
                                if (si.FromBillNo == list[i].FromBillNo && (si.SIStatus == 2 || si.SIStatus == 3 || si.SIStatus == 5))
                                {
                                    existNCcode += list[i].FromBillNo + ",";
                                    break;
                                }
                                else if (si.FromBillNo == list[i].FromBillNo && si.SIStatus != 4)
                                {
                                    delList.Add(si);
                                    break;
                                }
                            }
                        }

                        if (existNCcode != string.Empty)
                        {
                            existNCcode = existNCcode.Substring(0, existNCcode.Length - 1);
                            msg         = "保存失败!。用友系统中订单数据(" + existNCcode + ")存在于RFID系统中且已开始其他操作。";
                            return(false);
                        }

                        //删除数据库中原有的数据
                        if (delList.Count != 0)
                        {
                            foreach (StockIn delSI in delList)
                            {
                                foreach (StockIn newSI in list)
                                {
                                    //把旧的入库单号保留到新的单上
                                    if (newSI.FromBillNo == delSI.FromBillNo)
                                    {
                                        newSI.SICode = delSI.SICode;
                                        break;
                                    }
                                }
                                context.StockIn.DeleteObject(delSI);
                                context.SaveChanges();
                            }
                        }

                        //其加入数据库
                        foreach (StockIn newModel in list)
                        {
                            //生成入库单号
                            if (newModel.SICode == null)
                            {
                                newModel.SICode = KeyGenerator.Instance.GetStockInKey();
                            }

                            //搜索对应的采购订单详细信息
                            List <StockDetail> lstStockDetail = new List <StockDetail>();
                            if (GetNCDataDetailJoinRFID(out lstStockDetail, out msg, newModel.FromBillNo, newModel.SICode, newModel.WHCode))
                            {
                                foreach (StockDetail detail in lstStockDetail)
                                {
                                    newModel.StockDetail.Add(detail);
                                }
                            }
                            else
                            {
                                //msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                                return(false);
                            }

                            context.StockIn.AddObject(newModel);
                        }

                        //提交变更
                        int AffectRowsCount = context.SaveChanges();
                        msg = "保存成功!影响行数:" + AffectRowsCount.ToString();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "OtherStockInBill SaveToRFID方法出错", ex);
                msg = "OtherStockInBill SaveToRFID方法出错" + ex.Message;
                return(false);
            }
        }
Exemple #20
0
        //保存分配量
        bool SaveAllocate(GridViewRow editRow, out string saveMsg)
        {
            System.Text.StringBuilder checkMsg = new System.Text.StringBuilder();
            System.Text.StringBuilder LogMsg   = new System.Text.StringBuilder();


            //商品编码
            Label lblCargoCode = editRow.FindControl("lblCargoCode") as Label;

            if (lblCargoCode == null)
            {
                checkMsg.Append("未能获取商品编码");
                checkMsg.Append(Environment.NewLine);
            }

            //结存数量
            TextBox tbxRowTotal = editRow.FindControl("tbxRowTotal") as TextBox;

            if (tbxRowTotal == null)
            {
                checkMsg.Append("未能获取结存数量.");
                checkMsg.Append(Environment.NewLine);
            }

            //渠道部分配量
            TextBox tbxRowDeptChannelAllocation = editRow.FindControl("tbxRowDeptChannelAllocation") as TextBox;

            if (tbxRowDeptChannelAllocation == null)
            {
                checkMsg.Append("未能获取渠道部分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //销售部分配量
            TextBox tbxRowDeptSaleAllocation = editRow.FindControl("tbxRowDeptSaleAllocation") as TextBox;

            if (tbxRowDeptSaleAllocation == null)
            {
                checkMsg.Append("未能获取销售部分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //零售中心分配量
            TextBox tbxRowDeptRetailAllocation = editRow.FindControl("tbxRowDeptRetailAllocation") as TextBox;

            if (tbxRowDeptRetailAllocation == null)
            {
                checkMsg.Append("未能获取零售中心分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //电子商务分配量
            TextBox tbxRowDeptECAllocation = editRow.FindControl("tbxRowDeptECAllocation") as TextBox;

            if (tbxRowDeptECAllocation == null)
            {
                checkMsg.Append("未能获取电子商务分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //公用部门分配量
            TextBox tbxRowDeptPublicAllocation = editRow.FindControl("tbxRowDeptPublicAllocation") as TextBox;

            if (tbxRowDeptPublicAllocation == null)
            {
                checkMsg.Append("未能获取公用部门分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //机动量
            TextBox tbxRowVariation = editRow.FindControl("tbxRowVariation") as TextBox;

            if (tbxRowVariation == null)
            {
                checkMsg.Append("未能获取机动量.");
                checkMsg.Append(Environment.NewLine);
            }

            if (checkMsg.Length > 0)
            {
                saveMsg = checkMsg.ToString();
                return(false);
            }


            try
            {
                DAL.GoldEntities context = new GoldEntities();

                string cargoCode = lblCargoCode.Text;
                LogMsg.Append("商品编码为");
                LogMsg.Append(lblCargoCode.Text);

                Cargos UpdateCargos = (from r in context.Cargos where r.CargoCode == lblCargoCode.Text.Trim() select r).FirstOrDefault <Cargos>();
                LogMsg.Append(" 原商品结存数量为");
                LogMsg.Append(UpdateCargos.Total.ToString());
                UpdateCargos.Total = int.Parse(tbxRowTotal.Text);
                LogMsg.Append("。更新后商品结存数量为");
                LogMsg.Append(UpdateCargos.Total.ToString());

                LogMsg.Append(" 原商品机动量为");
                LogMsg.Append(UpdateCargos.Variation.ToString());
                UpdateCargos.Variation = int.Parse(tbxRowVariation.Text);
                LogMsg.Append("。更新后商品机动量为");
                LogMsg.Append(UpdateCargos.Variation.ToString());

                //新增或更新渠道部分配量
                string DeptChannelNo = "20103";
                SetNewOrUpdateModel(DeptChannelNo, cargoCode, int.Parse(tbxRowDeptChannelAllocation.Text), ref LogMsg, ref context);


                //新增或更新销售部分配量
                string DeptSaleNo = "20102";
                SetNewOrUpdateModel(DeptSaleNo, cargoCode, int.Parse(tbxRowDeptSaleAllocation.Text), ref LogMsg, ref context);


                //新增或更新零售中心部分配量
                string DeptRetailNo = "20105";//零售中心这里对应营业部
                SetNewOrUpdateModel(DeptRetailNo, cargoCode, int.Parse(tbxRowDeptRetailAllocation.Text), ref LogMsg, ref context);


                //新增或更新电子商务分配量
                string DeptECNo = "20110";
                SetNewOrUpdateModel(DeptECNo, cargoCode, int.Parse(tbxRowDeptECAllocation.Text), ref LogMsg, ref context);


                //新增或更新公用部门分配量
                string DeptPublicNo = "99999";
                SetNewOrUpdateModel(DeptPublicNo, cargoCode, int.Parse(tbxRowDeptPublicAllocation.Text), ref LogMsg, ref context);


                //以上新增和更新使用隐式事务
                int affectRows = context.SaveChanges();
                saveMsg = "影响行数:" + affectRows.ToString();

                context.Dispose();

                return(affectRows > 0 ? true : false);
            }
            catch (Exception ex)
            {
                saveMsg = Utility.LogHelper.GetExceptionMsg(ex);

                return(false);
            }
        }
Exemple #21
0
        /// <summary>
        /// 将从用友获取的DataTable数据保存到RFID系统
        /// </summary>
        /// <param name="dt">从用友获取的DataTable数据</param>
        /// <param name="msg">信息提示</param>
        /// <returns>true成功,false失败</returns>
        public override bool SaveToRFID(System.Data.DataTable dt, out string msg)
        {
            msg = "";
            try
            {
                string        convertMsg = "";
                List <Cargos> list       = GetModelFromDataTable(dt, out convertMsg);
                if (list.Count == 0)
                {
                    msg = "获取用友系统数据失败!详细信息:" + convertMsg;
                    return(false);
                }
                else
                {
                    using (GoldEntities context = new GoldEntities())
                    {
                        //查询系统中所有仓库编码
                        List <string> RFIDKeyList = (from r in context.Cargos select r.CargoCode).ToList <string>();

                        //判断价格信息中商品是否在RFID系统中存在,若不存在则不允许导入
                        StringBuilder strNotExistInRFIDCargo = new StringBuilder();
                        foreach (Cargos c in list)
                        {
                            if (RFIDKeyList.Contains(c.CargoCode) == false)
                            {
                                if (strNotExistInRFIDCargo.Length > 0)
                                {
                                    strNotExistInRFIDCargo.Append(",");
                                }
                                strNotExistInRFIDCargo.Append(c.CargoCode);
                            }
                        }
                        if (strNotExistInRFIDCargo.Length > 0)
                        {
                            msg  = "用友系统中下列商品在RFID系统中不存在,请先导入商品资料信息,然后导入价格信息! ";
                            msg += strNotExistInRFIDCargo.ToString();
                            return(false);
                        }

                        //变量过滤后的实体集,将其加入数据库
                        foreach (Cargos newModel in list)
                        {
                            //context.Cargos.AddObject(newModel);
                            Cargos existCargos = (from r in context.Cargos where r.CargoCode == newModel.CargoCode select r).FirstOrDefault <Cargos>();

                            existCargos.Price1 = newModel.Price1;//更新价格信息
                            existCargos.Price2 = newModel.Price2;
                            existCargos.Price3 = newModel.Price3;
                            existCargos.Price4 = newModel.Price4;
                            existCargos.Price5 = newModel.Price5;
                        }

                        //提交变更
                        int AffectRowsCount = context.SaveChanges();
                        msg = "保存成功!影响行数:" + AffectRowsCount.ToString();
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "CargoInfo SaveToRFID方法出错", ex);
                return(false);
            }
        }
Exemple #22
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            //switch (e.CommandName)
            //{
            //    case "Select":
            //        string userName = e.CommandArgument.ToString();
            //        string[] userRoles = Roles.GetRolesForUser(userName);
            //        SetRolesCheckList(userRoles);
            //        FormView2.ChangeMode(FormViewMode.ReadOnly);
            //        break;

            //}

            if (e.CommandName == "Select")
            {
                string   userName  = e.CommandArgument.ToString();
                string[] userRoles = Roles.GetRolesForUser(userName);
                SetRolesCheckList(userRoles);
                FormView2.ChangeMode(FormViewMode.ReadOnly);
            }
            else if (e.CommandName == "ResetPassword")
            {
                try
                {
                    //注意必须保证web.config中membership的配置为enablePasswordReset="true" requiresQuestionAndAnswer="false"

                    string                    userName        = e.CommandArgument.ToString();
                    MembershipUser            membershipUser  = Membership.GetUser(userName);
                    string                    newTempPassword = membershipUser.ResetPassword();
                    bool                      result          = membershipUser.ChangePassword(newTempPassword, "123456");
                    System.Text.StringBuilder strMsg          = new System.Text.StringBuilder();
                    strMsg.Append("用户[");
                    strMsg.Append(userName);
                    strMsg.Append("]密码");
                    if (result)
                    {
                        strMsg.Append("重置成功!新密码为[123456]");
                    }
                    else
                    {
                        strMsg.Append("重置失败!");
                    }
                    DAL.CommonConvert.ShowMessageBox(this.Page, strMsg.ToString());

                    //记录日志
                    if (Session["UserName"] != null)
                    {
                        strMsg.Append("    重置操作员:");
                        strMsg.Append(Session["UserName"].ToString());
                    }
                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Info, strMsg.ToString());
                }
                catch (Exception ex)
                {
                    DAL.CommonConvert.ShowMessageBox(this.Page, "密码重置操作失败!");
                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "密码重置", ex);
                }
            }
            else if (e.CommandName == "DeleteUser")
            {
                try
                {
                    string userID    = e.CommandArgument.ToString();
                    bool   delResult = Membership.DeleteUser(userID);//先删除Membership中用户
                    if (delResult)
                    {
                        using (GoldEntities context = new GoldEntities())
                        {
                            Users delUser = (from r in context.Users where r.UserId == userID select r).FirstOrDefault <Users>();
                            context.Users.DeleteObject(delUser);

                            int delRow = context.SaveChanges();
                            if (delRow > 0)
                            {
                                string msg = "用户[" + userID + "]删除成功!";
                                DAL.CommonConvert.ShowMessageBox(this.Page, msg);
                            }
                            else
                            {
                                DAL.CommonConvert.ShowMessageBox(this.Page, "删除失败!");
                            }

                            GridViewBind();//删除后重新绑定数据
                        }
                    }
                    else
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "删除失败!");
                    }
                }
                catch (Exception ex)
                {
                    string msg = Utility.LogHelper.GetExceptionMsg(ex).Replace("\r", "").Replace("\n", "");
                    DAL.CommonConvert.ShowMessageBox(this.Page, "更新失败!详细信息:" + msg);
                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "更新用户失败!", ex);
                }
            }
        }
Exemple #23
0
        //结束盘点任务
        protected void btnFinish_Click(object sender, EventArgs e)
        {
            try
            {
                lblGridViewMsg.Text = "";


                using (GoldEntities context = new GoldEntities())
                {
                    string scpCode = lblSCPCodeShow.Text;
                    foreach (GridViewRow row in gv_CargoList.Rows)
                    {
                        /*
                         * lblSCPCode
                         * lblDetailRowNumber
                         * lblNumPlan
                         * lblPeriodInNum
                         * lblPeriodOutNum
                         * lblNumActual
                         * lblNumDifference
                         */

                        Label lblDetailRowNumber = row.FindControl("lblDetailRowNumber") as Label;
                        //Label lblNumPlan = row.FindControl("lblNumPlan") as Label;
                        Label lblPeriodInNum  = row.FindControl("lblPeriodInNum") as Label;
                        Label lblPeriodOutNum = row.FindControl("lblPeriodOutNum") as Label;
                        //Label lblNumActual = row.FindControl("lblNumActual") as Label;
                        Label lblNumDifference = row.FindControl("lblNumDifference") as Label;


                        string DetailRowNumber = lblDetailRowNumber.Text.Trim();
                        //double NumPlan=0;
                        double PeriodInNum  = 0;
                        double PeriodOutNum = 0;
                        //double NumActual=0;
                        double NumDifference = 0;

                        //if(lblNumActual!=null&&lblNumActual.Text.Trim()!="")
                        //    NumActual=double.Parse(lblNumActual.Text);
                        if (lblPeriodInNum != null && lblPeriodInNum.Text.Trim() != "")
                        {
                            PeriodInNum = double.Parse(lblPeriodInNum.Text);
                        }
                        if (lblPeriodOutNum != null && lblPeriodOutNum.Text.Trim() != "")
                        {
                            PeriodOutNum = double.Parse(lblPeriodOutNum.Text);
                        }
                        if (lblNumDifference != null && lblNumDifference.Text.Trim() != "")
                        {
                            NumDifference = double.Parse(lblNumDifference.Text);
                        }

                        StockCountingDetail updateModel = (from r in context.StockCountingDetail where r.SCPCode == scpCode && r.DetailRowNumber == DetailRowNumber select r).FirstOrDefault();

                        updateModel.PeriodInNum   = PeriodInNum;
                        updateModel.PeriodOutNum  = PeriodOutNum;
                        updateModel.NumDifference = NumDifference;
                    }

                    StockCountingPlan planModel = (from r in context.StockCountingPlan where r.SCPCode == scpCode select r).FirstOrDefault();
                    planModel.SCPStatus = (int)EnumData.SCPStatusEnum.Finished;
                    if (Session["UserInfo"] != null)
                    {
                        Users LoginUser = Session["UserInfo"] as Users;
                        planModel.FinishPersonID   = LoginUser.UserId;
                        planModel.FinishPersonName = LoginUser.UserName;
                    }
                    planModel.FinishDate = DateTime.Now;

                    int AffectRowsCount = context.SaveChanges();
                    lblGridViewMsg.Text = "盘点计划单[" + scpCode + "]成功结束![影响行数" + AffectRowsCount.ToString() + "]";

                    btnFinish.Enabled  = false;
                    btnFinish.CssClass = "ButtonImageStyleEnableFalse";

                    GridViewBind();//删除完成后重新绑定盘点计划单
                }
            }
            catch (Exception ex)
            {
                lblGridViewMsg.Text = "操作失败![" + Utility.LogHelper.GetExceptionMsg(ex) + "]";
            }
        }