public bool CreateSample(QCSample sample) { return(sampledal.AddSample(sample)); }
protected void btnSave_Click(object sender, EventArgs e) { Sample sample = null; var dbProduct = new SampleDAL().GetSampleByCode(ddlProductCodeAndName.SelectedValue); if (dbProduct != null) { Page.RegisterClientScriptBlock("sample", "<script language='javascript'>alert('已经有相同的产品!');</script>"); return; } if (string.Equals(ViewType, "edit", StringComparison.OrdinalIgnoreCase)) { SampleDAL dal = new SampleDAL(); sample = dal.GetSampleById(SampleId); sample.MaterialCode = ddlProductCodeAndName.SelectedValue; sample.MaterialName = Utility.GetSelectedText(ddlProductCodeAndName); sample.SampleCode = txtSampleCode.Text; sample.SampleTexure = Utility.GetSelectedText(ddlTexure); sample.SampleLong = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : new Nullable <int>(); sample.SampleWidth = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : new Nullable <int>(); sample.SampleDeep = !string.IsNullOrEmpty(txtDeepth.Text) ? int.Parse(txtDeepth.Text) : new Nullable <int>(); sample.SampleColor = Utility.GetSelectedText(ddlColor); sample.SampleLocation = Utility.GetSelectedText(ddlLocation); sample.SampleSquare = !string.IsNullOrEmpty(txtSquare.Text) ? double.Parse(txtSquare.Text) : new Nullable <double>(); sample.Supplier = Utility.GetSelectedText(ddlSupplier); sample.PurchasePrice = !string.IsNullOrEmpty(txtPriceInM2.Text) ? double.Parse(txtPriceInM2.Text) : new Nullable <double>(); sample.PriceM = !string.IsNullOrEmpty(txtPriceM.Text) ? double.Parse(txtPriceM.Text) : new Nullable <double>(); sample.PriceM2 = !string.IsNullOrEmpty(txtPriceM2.Text) ? double.Parse(txtPriceM2.Text) : new Nullable <double>(); sample.Alias1 = txtAlias1.Text; sample.Alias2 = txtAlias2.Text; sample.SampleIntro = txtIntro.Text; if (!string.IsNullOrEmpty(filePic.FileName)) { string serverFilePath = string.Empty; Utility.UploadFile(filePic, "SampleImage", SourceNo, ref serverFilePath); sample.ImgPath = serverFilePath; } dal.Save(); } else if (string.Equals(ViewType, "create", StringComparison.OrdinalIgnoreCase)) { SampleDAL dal = new SampleDAL(); sample = new Sample(); sample.MaterialCode = ddlProductCodeAndName.SelectedValue; sample.MaterialName = Utility.GetSelectedText(ddlProductCodeAndName); sample.SampleCode = txtSampleCode.Text; sample.SampleTexure = Utility.GetSelectedText(ddlTexure); sample.SampleLong = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : new Nullable <int>(); sample.SampleWidth = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : new Nullable <int>(); sample.SampleDeep = !string.IsNullOrEmpty(txtDeepth.Text) ? int.Parse(txtDeepth.Text) : new Nullable <int>(); sample.SampleColor = Utility.GetSelectedText(ddlColor); sample.SampleLocation = Utility.GetSelectedText(ddlLocation); sample.SampleSquare = !string.IsNullOrEmpty(txtSquare.Text) ? double.Parse(txtSquare.Text) : new Nullable <double>(); sample.Supplier = Utility.GetSelectedText(ddlSupplier); sample.PurchasePrice = !string.IsNullOrEmpty(txtPriceInM2.Text) ? double.Parse(txtPriceInM2.Text) : new Nullable <double>(); sample.PriceM = !string.IsNullOrEmpty(txtPriceM.Text) ? double.Parse(txtPriceM.Text) : new Nullable <double>(); sample.PriceM2 = !string.IsNullOrEmpty(txtPriceM2.Text) ? double.Parse(txtPriceM2.Text) : new Nullable <double>(); sample.Alias1 = txtAlias1.Text; sample.Alias2 = txtAlias2.Text; sample.SampleIntro = txtIntro.Text; if (!string.IsNullOrEmpty(filePic.FileName)) { string serverFilePath = string.Empty; Utility.UploadFile(filePic, "SampleImage", SourceNo, ref serverFilePath); sample.ImgPath = serverFilePath; } dal.AddSample(sample); dal.Save(); } if (string.IsNullOrEmpty(CloseAfter)) { Response.Redirect(string.Format("productform.aspx?type=s&id={0}&viewtype=edit", sample.Sample_Id)); } else { Page.ClientScript.RegisterClientScriptBlock(typeof(FinishProductEditControl), "closecreate", "javascript:closeWindow();"); } }