Example #1
0
        private void savebtn_Click(object sender, EventArgs e)
        {
            if (trackserial.Checked && (SerialPrefix == "" || SerialPrefix == null))
                MessageBox.Show("Cannot use null serial prefix.  Set the prefix or uncheck 'Track Serial Number'", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {
                try
                {
                    //Commit Part Changes

                    Part Part = new Part(DataList.EpicConn);

                    PartDataSet Pdata = new PartDataSet();

                    //Pdata = (PartDataSet)DL.PartSearchDataSet("");

                    string serialWarning;

                    string questionString;

                    bool multipleMatch;

                    string PartNumber = Partnumber_txt.Text;

                    DataViewRowState DRState;

                    if (!DataList.PartExists(PartNumber))
                    {
                        Part.GetPartXRefInfo(ref PartNumber, "", "", out serialWarning, out questionString, out multipleMatch);

                        Part.GetNewPart(Pdata);

                        Part.ChangePartNum(PartNumber, Pdata);

                        DRState = DataViewRowState.Added;
                    }
                    else
                    {
                        Pdata = Part.GetByID(PartNumber);

                        DRState = DataViewRowState.Unchanged;

                        #region Clear Bflush/SN Settings

                        try
                        {
                            DataList.UpdateDatum(Pdata, "Part", 0, "TrackSerialNum", false.ToString());

                            DataList.UpdateDatum(Pdata, "Part", 0, "UseMaskSeq", false.ToString());

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PartTrackSerialNum", false.ToString());

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "BackFlush", false.ToString());

                            Part.Update(Pdata);

                            Pdata = Part.GetByID(PartNumber);
                        }
                        catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }

                        #endregion
                    }

                    Pdata = UpdateDataSet(Pdata, DRState);

                    //Add data to allow BO to create plant tables
                    try
                    {
                        Part.Update(Pdata);

                        if (bflush_chk.Checked)
                        {
                            //try to eliminate backflush if necessary
                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "BackFlush", bflush_chk.Checked.ToString());
                        }
                        Part.Update(Pdata);
                    }
                    catch (Exception ex) { System.Diagnostics.Debug.Print(ex.Message); }

                    if (trackserial.Checked)
                    {
                        Pdata = Part.GetByID(PartNumber);

                        try
                        {
                            Part.ChangePartTrackSerialNum(trackserial.Checked, Pdata);
                        }
                        catch
                        {
                            //If the neat process fails, do it the hard way.

                            DataList.UpdateDatum(Pdata, "Part", 0, "TrackSerialNum", true.ToString());

                            DataList.UpdateDatum(Pdata, "Part", 0, "UseMaskSeq", true.ToString());

                            DataList.UpdateDatum(Pdata, "Part", 0, "SNLastUsedSeq", "");

                            Part.Update(Pdata);

                            Pdata = Part.GetByID(PartNumber);

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "EnableSerialNum", true.ToString());

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PartTrackSerialNum", true.ToString());

                            try
                            {
                                DataList.UpdateDatum(Pdata, "PartPlant", 0, "PhantomBOM", false.ToString());
                            }
                            catch { }

                            Part.Update(Pdata);

                            Pdata = Part.GetByID(PartNumber);
                        }

                        DataList.UpdateDatum(Pdata, "Part", 0, "UseMaskSeq", true.ToString());
                    }

                    //retrieve the new copy of the data
                    Pdata = Part.GetByID(PartNumber);

                    if (whse_cbo.Items.Count > 0)
                    {
                        Part.Update(Pdata);

                        for (int i = 0; i < whse_cbo.Items.Count; i++)
                        {
                            whse_cbo.SelectedIndex = i;

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PrimWhse", whse_cbo.SelectedValue.ToString());

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PrimWhseDescription", whse_cbo.Text);

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "DBRowIdent", null);

                            //if (trackserial.Checked)

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PartTrackSerialNum", trackserial.Checked.ToString());
                        }

                        if (trackserial.Checked)
                        {
                            Part.ChangePartSNBaseDataType("MASK", Pdata);

                            Part.ChangeSNMask(SerialMask, Pdata);
                        }

                        Part.Update(Pdata);

                        DataList.UpdateDatum(Pdata, "PartPlant", 0, "BackFlush", bflush_chk.Checked.ToString());

                        if (planner_cbo.Enabled)
                        {
                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PersonID", planner_cbo.Text);

                            DataList.UpdateDatum(Pdata, "PartPlant", 0, "PersonName", planner_cbo.Text);
                        }

                        //Update with warehouse information
                        Part.Update(Pdata);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                finally
                {
                    DataList.EpicClose();

                    this.Close();
                }
            }
        }