示例#1
0
        private void TransferItem(clsListItemMain itm)
        {
            try
            {
                using (var db = new Gobibase())
                {
                    if (Transactionid == 0)
                    {
                        Transactionid = CFunctions.GetLastMassCounter();
                        CFunctions.SetLastMassCounter(1);
                    }

                    SqlConnection conn = new SqlConnection(db.Connection.ConnectionString);
                    SqlCommand    cmd  = new SqlCommand(@"INSERT INTO [t_orderlist] ([transactionid],[zahialgach],[zahnum],[createdU],[createdDate],[itemcode]) VALUES (@p1,@p2,@p3,@p4,@p5,@p6)", conn);
                    cmd.Parameters.Add("@p1", SqlDbType.Int).Value          = Transactionid;
                    cmd.Parameters.Add("@p2", SqlDbType.NVarChar, 50).Value = txtOrder.Text;
                    cmd.Parameters.Add("@p3", SqlDbType.NVarChar, 50).Value = txtZahnum.Text;
                    cmd.Parameters.Add("@p4", SqlDbType.NVarChar, 50).Value = frmMain.cLoginUser.Uname;
                    cmd.Parameters.Add("@p5", SqlDbType.NVarChar, 50).Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    cmd.Parameters.Add("@p6", SqlDbType.NVarChar, 50).Value = itm.Itemcode;
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Aлдаа гарлаа!" + Environment.NewLine + ex.Message, "Анхааруулга", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#2
0
        private void btnCreateCode_Click(object sender, EventArgs e)
        {
            lblMsg.Text = "";
            if (txtZahnum.Text == null || txtZahnum.Text == "")
            {
                lblMsg.Text = "Захиалгын дугаар хоосон байна.";
                txtZahnum.Focus();
                return;
            }
            if (txtOrder.Text == null || txtOrder.Text == "")
            {
                lblMsg.Text = "Захиалгын нэр хоосон байна.";
                txtOrder.Focus();
                return;
            }

            if (list_main.Count() > 0 && MessageBox.Show("Шинэ Itemcode-г хадгалах уу?", "Анхааруулга", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                if (Transactionid == 0)
                {
                    Transactionid = CFunctions.GetLastMassCounter();
                    CFunctions.SetLastMassCounter(1);
                }

                Cursor.Current = Cursors.WaitCursor;
                using (var db = new Gobibase())
                {
                    SqlConnection conn = new SqlConnection(db.Connection.ConnectionString);
                    conn.Open();
                    SqlCommand     cmd = conn.CreateCommand();
                    SqlTransaction transaction;
                    transaction = conn.BeginTransaction("AddTrans");
                    cmd.Parameters.Add("@p1", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p2", SqlDbType.NVarChar, 100);
                    cmd.Parameters.Add("@p3", SqlDbType.NVarChar, 100);
                    cmd.Parameters.Add("@p4", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p5", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p6", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p7", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p8", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p9", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p10", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p11", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p12", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p13", SqlDbType.DateTime);
                    cmd.Parameters.Add("@p14", SqlDbType.Int);
                    cmd.Parameters.Add("@p15", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p16", SqlDbType.NVarChar, 50);
                    cmd.Parameters.Add("@p17", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p18", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p19", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p20", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p21", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p22", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p23", SqlDbType.NVarChar, 80);
                    cmd.Parameters.Add("@p24", SqlDbType.Int);
                    cmd.Parameters.Add("@p25", SqlDbType.NVarChar, 500);

                    cmd.Connection  = conn;
                    cmd.Transaction = transaction;

                    try
                    {
                        foreach (clsListItemMain i in list_main.ToList())
                        {
                            cmd.CommandText              = @"INSERT INTO [t_main] ([itemcode],[itemname],[itemnameen],[lev1],[lev2],[lev3],[lev4],[lev5],[lev6]
,[lev7],[lev8],[lev9],[createddate],[createduser],[color1],[color2],[l1n],[l2n],[l3n],[l6n],[l8n],[l9n],[zagvartype],[itemcode_eh],[version_eh],[colorpart]) 
VALUES (@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9,@p10,@p11,@p12,@p13,@p14,@p15,@p16,@p17,@p18,@p19,@p20,@p21,@p22,N'Масс',@p23,@p24,@p25)";
                            cmd.Parameters["@p1"].Value  = i.Itemcode;
                            cmd.Parameters["@p2"].Value  = i.Itemname;
                            cmd.Parameters["@p3"].Value  = i.Itemnameen;
                            cmd.Parameters["@p4"].Value  = i.Lev1;
                            cmd.Parameters["@p5"].Value  = i.Lev2;
                            cmd.Parameters["@p6"].Value  = i.Lev3;
                            cmd.Parameters["@p7"].Value  = i.Lev4;
                            cmd.Parameters["@p8"].Value  = i.Lev5;
                            cmd.Parameters["@p9"].Value  = i.Lev6;
                            cmd.Parameters["@p10"].Value = i.Lev7;
                            cmd.Parameters["@p11"].Value = i.Lev8;
                            cmd.Parameters["@p12"].Value = i.Lev9;
                            cmd.Parameters["@p13"].Value = DateTime.Now;
                            cmd.Parameters["@p14"].Value = frmMain.UserID;
                            cmd.Parameters["@p15"].Value = i.Color1;
                            cmd.Parameters["@p16"].Value = i.Color2;
                            cmd.Parameters["@p17"].Value = i.L1n;
                            cmd.Parameters["@p18"].Value = i.L2n;
                            cmd.Parameters["@p19"].Value = i.L3n;
                            cmd.Parameters["@p20"].Value = i.L6n;
                            cmd.Parameters["@p21"].Value = i.L8n;
                            cmd.Parameters["@p22"].Value = i.L9n;
                            cmd.Parameters["@p23"].Value = i.Itemcode_eh;
                            cmd.Parameters["@p24"].Value = i.Version_eh;
                            cmd.Parameters["@p25"].Value = i.Colorpart;
                            cmd.ExecuteNonQuery();
                        }


                        foreach (clsListItemMain i in list_main.ToList())
                        {
                            cmd.CommandText = @"INSERT INTO [t_orderlist] ([transactionid],[zahialgach],[zahnum],[createdU],[createdDate],[itemcode],[colorpart]) 
VALUES (@p14,@p2,@p3,@p4,@p5,@p6,@p25)";
                            cmd.Parameters["@p14"].Value = Transactionid;
                            cmd.Parameters["@p2"].Value  = txtOrder.Text;
                            cmd.Parameters["@p3"].Value  = txtZahnum.Text;
                            cmd.Parameters["@p4"].Value  = frmMain.cLoginUser.Uname;
                            cmd.Parameters["@p5"].Value  = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                            cmd.Parameters["@p6"].Value  = i.Itemcode;
                            cmd.Parameters["@p25"].Value = i.Colorpart;
                            cmd.ExecuteNonQuery();
                        }

                        cmd.CommandText = "UPDATE t_orderlist set zahnum = @p3, zahialgach = @p2 where transactionid = @p14";
                        cmd.Parameters["@p14"].Value = Transactionid;
                        cmd.Parameters["@p2"].Value  = txtOrder.Text;
                        cmd.Parameters["@p3"].Value  = txtZahnum.Text;
                        cmd.ExecuteNonQuery();


                        transaction.Commit();

                        this.Tag = "ok";

                        list_main.Clear();

                        gcMain.DataSource       = list_main.ToList();
                        gvMain.FocusedRowHandle = gvMain.DataRowCount - 1;

                        conn.Close();

                        GetItemcodeRowdata();
                    }
                    catch (Exception ex)
                    {
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Алдаа гарлаа!" + Environment.NewLine + ex.Message, "Анхааруулга", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        try
                        {
                            transaction.Rollback();
                        }
                        catch (Exception ex2)
                        {
                            MessageBox.Show("Rollback Exception Type: {0}", ex2.GetType().ToString() + Environment.NewLine + "  Message: " + ex2.Message);
                        }
                    }
                }
            }
        }