当前位置: 首页>>代码示例>>C#>>正文


C# Factory.GetByPrimaryKey方法代码示例

本文整理汇总了C#中System.Factory.GetByPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# Factory.GetByPrimaryKey方法的具体用法?C# Factory.GetByPrimaryKey怎么用?C# Factory.GetByPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Factory的用法示例。


在下文中一共展示了Factory.GetByPrimaryKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnSave_Click

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (btnDelete.Enabled == false)
                {
                    List<Factory> listFac = new List<Factory>();
                    listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList();
                    if (listFac.Count > 0)
                    {
                        RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");");
                        return;
                    }
                    Factory fac = new Factory();
                    fac.No = txtNo.Text;
                    fac.CompanyId = int.Parse(GetCompany());
                    fac.Name = txtName.Text;
                    fac.isDeleted = false;
                    //fac.ImageFile = txtImgName.Text;
                    fac.CreateAccount = fac.ModifiedAccount = this.User.Identity.Name;
                    int id = Factory.InsertWithIndentity(fac);
                    fac.ImageFile = id.ToString()+".png";
                    fac.Update();

                    string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, id, txtName.Text);
                    if (!Directory.Exists(Server.MapPath(pathNew))) //(!Directory.Exists(Server.MapPath("~/Portal\\Images\\Factory\\")))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)"));
                    }
                    string path = Server.MapPath(pathNew);//"~/Portal\\Images\\Factory\\");
                    //string filename = imgFactory.ImageUrl;
                    string base64 = (string)ViewState["img"];
                    byte[] b = Convert.FromBase64String(base64);
                    System.IO.File.WriteAllBytes(path + "/" + id +".png", b);
                }
                else
                {

                    Factory fac = new Factory();
                    fac.FactoryId = int.Parse(hiddenFacID.Value);
                    fac.CompanyId = int.Parse(GetCompany());
                    fac = fac.GetByPrimaryKey();
                    if (fac.Name.Trim() != txtName.Text.Trim())
                    {
                        List<Factory> listFac = new List<Factory>();
                        listFac = Factory.GetAll().Where(l => l.Name.Trim().ToLower() == txtName.Text.Trim().ToLower()).ToList();
                        if (listFac.Count > 0)
                        {
                            RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), string.Format(GetResource("CheckName"), lblFactoryName.Text)) + "\");");
                            return;
                        }
                    }
                    fac.ModifiedAccount = this.User.Identity.Name;
                    fac.No = txtNo.Text;
                    fac.Name = txtName.Text;
                    fac.ImageFile = hiddenFacID.Value.ToString()+".png";
                    fac.Update();
                    string pathNew = Constant.PORTAL + GetCompanyPath() + string.Format(Constant.PATH_FACTORY, hiddenFacID.Value, txtName.Text);
                    if (!Directory.Exists(Server.MapPath(pathNew))) //("~/Portal\\Images\\Factory\\")))
                    {
                        Directory.CreateDirectory(Server.MapPath(pathNew)); //("~/Portal\\Images\\Factory\\)"));
                    }
                    string path = Server.MapPath(pathNew); //("~/Portal\\Images\\Factory\\");
                    if (ViewState["img"] != null)
                    {
                        string base64 = (string)ViewState["img"];
                        byte[] b = Convert.FromBase64String(base64);
                        System.IO.File.WriteAllBytes(path + "/" + int.Parse(hiddenFacID.Value) + ".png", b);

                    }
                }
                ViewState.Remove("img");
                panelEdit.Visible = false;
                panelMain.Visible = true;
                Search();
            }
            catch (Exception ex)
            {
                RegisterStartupScript("alert(\"" + GetJSMessage(GetResource("Title_Error"), ex.Message) + "\");");
                logger.Error("Erorr btnSave_click", ex);
            }
        }
开发者ID:dtafe,项目名称:WorkNC,代码行数:82,代码来源:MstFactory.aspx.cs


注:本文中的System.Factory.GetByPrimaryKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。